Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: PBR Preview Plugin #1

Merged
merged 38 commits into from
May 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
765f5ab
feat: PBR Preview plugin
jasonjgardner May 16, 2024
6e9f45e
upd: Add channel dialog
jasonjgardner May 17, 2024
cbed40f
feat: Add PBR preview controls
jasonjgardner May 17, 2024
70001ca
upd: Use Preview class for PBR Mode
jasonjgardner May 19, 2024
80c6961
feat: Material panel
jasonjgardner May 20, 2024
f8fd370
fix: Toggle off
jasonjgardner May 20, 2024
5ca3e3f
feat: Added more display settings controls
jasonjgardner May 20, 2024
a2b05d6
upd: Render on display changes
jasonjgardner May 20, 2024
774675f
fix: Updated localStorage logic
jasonjgardner May 20, 2024
8a2402d
chore: Apply formatting / Remove unused code
jasonjgardner May 20, 2024
4006a27
feat: Generate MER map
jasonjgardner May 21, 2024
27ab98d
upd: Hide grid in PBR mode
jasonjgardner May 21, 2024
b17510e
feat: Plugin icon
jasonjgardner May 21, 2024
67afc33
feat: Generate texture set JSON
jasonjgardner May 21, 2024
f22eaae
feat: Generate normal map from height map
jasonjgardner May 21, 2024
e2de622
feat: Add decode MER option
jasonjgardner May 21, 2024
6bb74b3
feat: Get emissive color from albedo
jasonjgardner May 21, 2024
a4c2178
fix: Render nearest neighbor on textures
jasonjgardner May 22, 2024
77104cc
feat: PBR view in edit and paint modes
jasonjgardner May 22, 2024
3a8d77c
upd: Redraw canvas on update
jasonjgardner May 22, 2024
b364864
upd: Optimized event subscription
jasonjgardner May 22, 2024
24ca0cc
upd: Avoid empty albedo in edit/paint mode
jasonjgardner May 22, 2024
1402d07
upd: Use layers for material channels
jasonjgardner May 23, 2024
60e675f
upd: Activate project elements / Update faces
jasonjgardner May 23, 2024
1c84cab
upd: Toggle channels with layer
jasonjgardner May 23, 2024
6293836
refactor: OOP material
jasonjgardner May 24, 2024
776fcbd
upd: BB UI / Action-based functions
jasonjgardner May 25, 2024
1521d23
fix: Corrected deactivation function
jasonjgardner May 25, 2024
ab6fa70
fix: Channel unassignment
jasonjgardner May 25, 2024
8e83a35
fix: MER generation
jasonjgardner May 25, 2024
a890d77
upd: Unassign old channels
jasonjgardner May 25, 2024
f6ed5cc
upd: Correct texture set export
jasonjgardner May 25, 2024
8d2a1f2
fix: Hide extended project settings
jasonjgardner May 25, 2024
9f9bb3f
upd: Features outline in about.md
jasonjgardner May 26, 2024
bf13186
chore: Add changelog & descriptions
jasonjgardner May 26, 2024
9187a63
upd: Add project PBR mode
jasonjgardner May 26, 2024
f882a56
Merge branch 'JannisX11:master' into pbr-layers-actions
jasonjgardner May 26, 2024
1da7444
upd: Plugin about section
jasonjgardner May 26, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
674 changes: 674 additions & 0 deletions plugins/pbr_preview/LICENSE.MD

Large diffs are not rendered by default.

84 changes: 84 additions & 0 deletions plugins/pbr_preview/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
__Create textures for Bedrock shaders with PBR support (Deferred Rendering / RTX)__

## Features

### PBR Material Preview
- Preview PBR textures in Edit, Paint, and Animate mode.
- Infers texture channels based on naming conventions when no channel has been explicitly defined. Intended for previewing imported Bedrock PBR textures.

> _PBR:_ Physically based rendering

#### Auto-Updated Preview
- PBR materials are updated with every edit to provide a <small>(nearly)</small> live painting preview of the material in Blockbench.

### MER Maps
> _MER:_ Metallic, emissive, and roughness maps assigned to red, green, and blue channels respectively. It is the format used in Bedrock texture sets.
#### Decode MER
- MERs can be inferred and decoded automatically when PBR mode is enabled.
- Decoding can be _slow_ on large textures (1024x+).
- Assign an albedo map prior to decoding a MER to extract the emissive color.

#### Export MER
- Compiles metal, emissive and roughness channels into MER texture.
- (Emissive colors will be lost upon export. Use grayscale values in emissive channels for accurate brightness levels.)

### Generate Normal Map
- Calculate normal map based on the assigned or inferred height map for the currently selected material/texture.

### Export Texture Set
- Create a `.texture_set.json` file for the project textures.
- Dialog allows defining values which can not be inferred from project.
- Exports MER in the process.

## Usage

### PBR Settings

This plugin adds the _PBR Settings_ panel, which controls enabling and disabling PBR materials in Blockbench previews.

#### Toggle PBR

- Use the _PBR Preview_ toggle to toggle or refresh the PBR preview. Also found in the _View_ menu.

#### Toggle Corrected Lighting

- Use the _Correct Lights_ toggle to enable or disable physically-corrected lighting in the preview scene. This may improve the appearance of reflective and emissive materials in the preview scene, but will dim the albedo/base color texture.

#### Tone Mapping

- The _Tone Mapping_ setting will apply various tone mapping techniques to the preview scene. Use the _Linear_ option to match the tone map used by most Bedrock shaders.

#### Exposure

- The scene exposure can be adjusted once a tone map technique is selected. Values range from -2.0 to 2.0.

### Channel Management

Control which textures or texture layers are used for PBR channels using the following methods:W

#### Channel Naming Convention

The plugin will assume that textures and layers which end in an underscore and a channel name are intended to be used as that channel. For example, `texture_roughness` will be used as the roughness map unless the channel has been manually assigned a texture.

#### Supported Channels
| Channel | Description | Colorspace |
|-----------|-------------|------------|
| `ao` | Ambient Occlusion | __BW__ |
| `albedo` | Albedo / Base Color | __RGB__ |
| `normal` | DirectX Normal Map | __RGB__ |
| `metalness` | Metallic map | __BW__ |
| `roughness` | Roughness map | __BW__ |
| `emissive` | Emissive map | Displayed in __RGB__; Exported as __BW__ in MER |
| `sss` | Subsurface Scattering | __BW__; Not supported by shader but exported in MER alpha channel |

#### Explicit Channel Assignment

Create a Texture Layer in Blockbench to enable channel assignment in PBR previews. Each channel can be selected from a menu and applied to the current material. The menu is visible in the _PBR Settings_ panel when in Paint mode. The menu options are also available in the _Image_ menu.

#### Removing Channel Assignment

Channels can be disabled by hiding or deleting the layer, or un-assigning the channel in the menu. Texture layers cannot be assigned to more than one channel. Assigning a layer to a new channel will clear the layer's current channel.

## Roadmap
- Java project support
- labPBR texture exports
15 changes: 15 additions & 0 deletions plugins/pbr_preview/changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"1.0.0": {
"title": "1.0.0",
"date": "2024-05-25",
"author": "Jason J. Gardner",
"categories": [
{
"title": "PBR plugin",
"list": [
"Initial release 🚀"
]
}
]
}
}
Binary file added plugins/pbr_preview/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions plugins/pbr_preview/members.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
maintainers:
- jasonjgardner
developers:
- jasonjgardner
1 change: 1 addition & 0 deletions plugins/pbr_preview/pbr_preview.js

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions src/pbr_preview/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
dist/
package-lock.json
4 changes: 4 additions & 0 deletions src/pbr_preview/.vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"editor.formatOnSave": true,
"editor.defaultFormatter": "esbenp.prettier-vscode"
}
25 changes: 25 additions & 0 deletions src/pbr_preview/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"name": "blockbench-pbr",
"version": "1.0.0",
"description": "PBR support for Blockbench",
"main": "./src/index.ts",
"scripts": {
"build": "esbuild src/index.ts --bundle --minify --outfile=../../plugins/pbr_preview/pbr_preview.js",
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "esbuild src/index.ts --bundle --sourcemap --outfile=../../plugins/pbr_preview/pbr_preview.js --watch",
"format": "prettier --write src/**/*.ts",
"dist": "npm run format && npm run build"
},
"keywords": [
"blockbench"
],
"author": "Jason Gardner",
"license": "MIT",
"devDependencies": {
"@types/three": "^0.157.0",
"blockbench-types": "4.9.0",
"esbuild": "0.19.4",
"prettier": "^3.2.5",
"typescript": "^5.2.2"
}
}
Loading