# render-composer

> Declarative graph-based render pipelines.

Latest version **0.2.8** (published 2022-10-19) · MIT license · 0 weekly downloads

## Install

```sh
npm install render-composer
pnpm add render-composer
yarn add render-composer
bun add render-composer
```

## Health

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

Positive: has types; esm support; no vulnerabilities.

Warnings: low downloads; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.8 |
| Published | 2022-10-19 |
| First published | 2022-07-23 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Dependencies | 7 |
| Unpacked size | 91.4 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Hendrik Mans |
| Maintainers | hendrik.mans |

## Links

- npm: https://www.npmjs.com/package/render-composer
- npm.io page: https://npm.io/package/render-composer

## Dependencies (7)

- [test](https://npm.io/package/test.md) ^3.2.1
- [fp-ts](https://npm.io/package/fp-ts.md) ^2.12.3
- [shader-composer](https://npm.io/package/shader-composer.md) ^0.4.4
- [@hmans/use-const](https://npm.io/package/@hmans/use-const.md) ^0.0.1
- [@hmans/use-mutable-list](https://npm.io/package/@hmans/use-mutable-list.md) ^0.0.2
- [@hmans/use-nullable-state](https://npm.io/package/@hmans/use-nullable-state.md) ^0.0.1
- [shader-composer-postprocessing](https://npm.io/package/shader-composer-postprocessing.md) ^0.0.1

## Recent versions

- 0.2.8 (latest) — 2022-10-19
- 0.0.0-canary-20221130162026 (canary) — 2022-11-30
- 0.0.0-canary-20221129151046 — 2022-11-29
- 0.0.0-canary-20221129141308 — 2022-11-29
- 0.2.7 — 2022-10-16
- 0.2.6 — 2022-10-12
- 0.2.5 — 2022-10-02
- 0.2.4 — 2022-09-24
- 0.2.3 — 2022-09-22
- 0.2.2 — 2022-09-17
- 0.0.0-canary-20220917133533 — 2022-09-17
- 0.0.0-canary-20220917133335 — 2022-09-17
- 0.2.1 — 2022-09-16
- 0.2.0 — 2022-09-16
- 0.1.6 — 2022-09-13
- … 7 more at https://npm.io/package/render-composer/versions

## README

# Render Composer

A pre-configured render pipeline for your react-three-fiber games. It is meant to provide some sane defaults for rendering your game, making it easy to make it look fancy, but also providing some tooling like a pre-render pass providing render and depth textures to shaders that need them.

## tl;dr

```tsx
import * as RC from "render-composer"

function App() {
  return (
    <RC.Canvas>
      <RC.RenderPipeline>
        {/* Just do normal R3F stuff inside. */}
        <directionalLight position={[30, 10, 10]} intensity={1.5} />
        <mesh>
          <icosahedronGeometry />
          <meshStandardMaterial color="hotpink" />
        </mesh>
      </RC.RenderPipeline>
    </RC.Canvas>
  )
}
```

## Depth and Scene Buffers

The render pipeline implemented by the `<RenderPipeline>` component splits rendering of the scene into two discrete render passes, the color and depth buffers of which are made available to objects rendered in the second pass. This allows you to render objects that require depth or color buffers to work (like transparent water with refraction and depth-based foam, or volumetric fog).

In order to make use of this functionality, you will have to do two things:

1. Make sure the meshes that consume these buffers are set to the `Layers.TransparentFX` layer. This will remove them from the scene pass and only render them in the effects pass.
2. Use the `useRenderPipeline` hook to get a reference to the depth and color textures.

```tsx
const StylizedWater = () => {
  const { depth, color } = useRenderPipeline()

  return <mesh layers-mask={1 << Layers.TransparentFX}>{/* ... */}</mesh>
}
```

## Customizing Canvas

`<RC.Canvas>` is just a thin wrapper around react-three-fiber's `<Canvas>` that applies some configuration that Render Composer needs to operate as expected. You can override any of the props if you want to:

```tsx
import * as RC from "render-composer"

function App() {
  return (
    <RC.Canvas frameloop="demand">
      <RC.RenderPipeline>{/* etc. */}</RC.RenderPipeline>
    </RC.Canvas>
  )
}
```

Alternatively, you may use your own `<Canvas>`; but if you do this, please make sure it sets the `flat` property:

```tsx
import { Canvas } from "@react-three/fiber"
import * as RC from "render-composer"

function App() {
  return (
    <Canvas flat>
      <RC.RenderPipeline>{/* etc. */}</RC.RenderPipeline>
    </Canvas>
  )
}
```

## Enabling React's StrictMode

During development of your application, it is recommended to use React's [Strict Mode](https://reactjs.org/docs/strict-mode.html). Unfortunately, enabling `<StrictMode>` at the root of your application will not enable it for any react-three-fiber canvases (one of which we're wrapping in `<RC.Canvas>`.) To enable StrictMode for your application, you either need to wrap the children of your canvas inside `<StrictMode>`, like so:

```tsx
import { StrictMode } from "react"
import * as RC from "render-composer"

function App() {
  return (
    <RC.Canvas>
      <StrictMode>
        <RC.RenderPipeline>{/* etc. */}</RC.RenderPipeline>
      </StrictMode>
    </RC.Canvas>
  )
}
```

Or, alternatively, use the `strict` prop on `<RC.Canvas>`, which will set up the StrictMode wrapper for you:

```tsx
import * as RC from "render-composer"

function App() {
  return (
    <RC.Canvas strict>
      <RC.RenderPipeline>{/* etc. */}</RC.RenderPipeline>
    </RC.Canvas>
  )
}
```

## Adding full-screen post-processing effects

Render Composer provides React component wrappers around (some of) the post-processing effects from [postprocessing]. In your project, just create additional effect passes as you see fit:

```tsx
import * as RC from "render-composer"

function App() {
  return (
    <RC.Canvas>
      <RC.RenderPipeline>
        <RC.EffectPass>
          <RC.SMAAEffect />
          <RC.SelectiveBloomEffect intensity={5} />
          <RC.VignetteEffect />
        </RC.EffectPass>

        {/* ...normal R3F stuff here. */}
      </RC.RenderPipeline>
    </RC.Canvas>
  )
}
```

These components expose the same props as the original postprocessing effects, but should all in all be considered work-in-progress.

## Custom Render Pipelines

TODO

## License

```
Copyright (c) 2022 Hendrik Mans

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
```

[postprocessing]: https://github.com/pmndrs/postprocessing

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