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 #545

Merged
merged 41 commits into from
Aug 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
c472b92
feat: PBR Preview Plugin (#1)
jasonjgardner May 26, 2024
6927ebe
fix: Toggle button condition
jasonjgardner May 26, 2024
18fc13e
fix: Disable conditions for MER export
jasonjgardner May 26, 2024
390e80b
fix: Change texture set format version
jasonjgardner May 26, 2024
0139629
fix: Add metalness/roughness base values
jasonjgardner May 27, 2024
05875de
upd: Global metal/roughness setting
jasonjgardner May 27, 2024
d93d643
feat: New material Action
jasonjgardner May 28, 2024
c54e051
upd: Add normal scale
jasonjgardner May 28, 2024
b6bf6db
feat: Material brush
jasonjgardner May 29, 2024
41f7cad
upd: Change display conditions
jasonjgardner May 29, 2024
08d484c
fix: Material brush paint on selected layer
jasonjgardner May 29, 2024
a40e640
upd: Improved controls and channel assignment
jasonjgardner May 30, 2024
f23bc5c
Merge branch 'JannisX11:master' into master
jasonjgardner May 30, 2024
9942879
feat: Texture baking (#2)
jasonjgardner Jun 1, 2024
0aba465
upd: labPBR support / Material presets (#3)
jasonjgardner Jun 5, 2024
70822e1
Merge remote-tracking branch 'upstream/master'
jasonjgardner Jun 6, 2024
040eccc
fix: Create MER output
jasonjgardner Jun 6, 2024
edc6af3
upd: Convert textures to material Action (#4)
jasonjgardner Jun 7, 2024
d0babc8
upd: Docs / Interface clean-up / AO generation (#5)
jasonjgardner Jun 10, 2024
bc191a5
upd: Optimize apply PBR material (#6)
jasonjgardner Jun 12, 2024
ebdb325
fix: Physically correct lighting toggle (#7)
jasonjgardner Jun 13, 2024
ccc9e34
chore: Commit build output
jasonjgardner Jun 13, 2024
6950ada
upd: Material brush size/softness (#8)
jasonjgardner Jun 17, 2024
3916622
Merge remote-tracking branch 'upstream/master'
jasonjgardner Jun 17, 2024
06106c8
fix: MER decoding
jasonjgardner Jun 17, 2024
3cfb1e9
Squashed commit of the following:
jasonjgardner Jun 17, 2024
a9e5d66
revert: Remove material preview
jasonjgardner Jun 17, 2024
e792e53
upd: Apply PBR on USDZ export
jasonjgardner Jun 17, 2024
fd66faa
upd: Change material texture icon
jasonjgardner Jun 17, 2024
f63b625
fix: New material texture normal map (#9)
jasonjgardner Jun 18, 2024
3d66662
fix: Channels panel lifecycle
jasonjgardner Jun 18, 2024
60a655e
docs: Add USDZ section
jasonjgardner Jun 18, 2024
2723050
feat: .bbmat format (#10)
jasonjgardner Jun 20, 2024
fc25a5b
upd: Normal map orientation (#11)
jasonjgardner Jun 20, 2024
3c47eb5
fix: Face update logic
jasonjgardner Jun 22, 2024
b9896ed
Merge remote-tracking branch 'upstream/master'
jasonjgardner Jun 22, 2024
c56669d
fix: Remove neutral tone mapping
jasonjgardner Jun 22, 2024
21db458
Merge remote-tracking branch 'upstream/master'
jasonjgardner Jul 10, 2024
64f0fe8
upd: Add Undo aspect
jasonjgardner Jul 12, 2024
bf53bf2
fix: Plugins conflict
jasonjgardner Jul 12, 2024
e6de06b
Fix plugins.json conflicts
JannisX11 Aug 24, 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
18 changes: 18 additions & 0 deletions plugins.json
Original file line number Diff line number Diff line change
Expand Up @@ -955,5 +955,23 @@
"dependencies": ["cem_template_loader"],
"creation_date": "2024-06-05",
"has_changelog": true
},
"pbr_preview": {
"title": "PBR Tools",
"author": "Jason J. Gardner",
"await_loading": true,
"creation_date": "2024-06-10",
"icon": "icon.png",
"description": "Create and view PBR materials in Blockbench. Export textures for Java and RenderDragon shaders.",
"has_changelog": true,
"website": "https://github.com/jasonjgardner/blockbench-plugins/",
"variant": "both",
"version": "1.1.0",
"tags": [
"Minecraft: Java Edition",
"Minecraft: Bedrock Edition",
"PBR"
],
"min_version": "4.10.4"
}
}
674 changes: 674 additions & 0 deletions plugins/pbr_preview/LICENSE.MD

Large diffs are not rendered by default.

206 changes: 206 additions & 0 deletions plugins/pbr_preview/about.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,206 @@
**Create and view PBR textures in Blockbench. Exports [USDZ](https://openusd.org/release/index.html) and in formats for labPBR
(Java) or RenderDragon (Bedrock) shaders**

> **_PBR:_ Physically based rendering**\
> Read the
> _[Intoduction to Physically Based Rendering](https://learn.microsoft.com/en-us/minecraft/creator/documents/rtxpbrintro?view=minecraft-bedrock-stable "View Minecraft Creator documentation article.")_
> article in the Minecraft Creator documentation if you are not already familiar
> with creating PBR content for Bedrock Edition. Visit the
> [shaderLABS wiki](https://shaderlabs.org/wiki/Main_Page) for more information
> on the labPBR material standard.

## Blockbench PBR Plugin 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 existing Bedrock and Java
PBR textures.
- Uses Blockbench's preview scenes as model environment map.
- PBR materials are updated with every edit to provide a 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.
- Channels extracted from a MER can be saved as either separate textures or into
separate layers in a single texture.

#### 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.

### Generate Ambient Occlusion Map

- Generate an AO map from the material's normal map. (AO available in some
labPBR shaders.)

### Texture Baking

- Bake a normal and emissive maps onto the base color channel.
- Output multiple light positions.
- Choose ambient light settings before baking.

### 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 and normal maps in the process.

### labPBR Specular/Normal Maps

- Export `_s` and `_n` files for PBR textures created in Blockbench.
- Decode existing, imported labPBR textures into PBR material channels.

### Material Brush

- Paint across multiple PBR channels simultaneously for a consistent material
output.
- Save material brush presets to a collection.
- Automatic PBR preview updates after every brush stroke.

### Export USDZ Scenes

- Adds new codec for exporting in USDZ format.

### `.bbmat` Codec

Reuse and share PBR materials in Blockbench with this custom file format.

## Usage

### PBR Controls

This plugin adds the _PBR Controls_ 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.

> <details>
> <summary>Usage Tip</summary>
> Toggling the PBR preview off and on may solve any texture discrepancies. Allowing the scene to render again will ensure all textures are up-to-date in the preview.
> </details>

#### 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_ select 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:

#### Create Material Texture

- Use the _Create Material Texture_ action to create a blank texture with PBR
material layers initialized.\
If an existing texture is selected, it will be used as the albedo channel in
the PBR material. If the project has other textures, include those textures in
the selection to have them automatically assigned to the new material's PBR
channels.

Follow these naming conventions to ensure the textures are assigned to the
appropriate channels when creating a new material:

#### 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 |

###### Supported Minecraft Shader Channels

RenderDragon and labPBR textures are automatically decoded and displayed when
the channels can be inferred based on the existence of MER, specular, or normal
maps. Some features are not supported by the Blockbench preview's shader, such
as AO and POM, but can still be decoded/encoded during texture import/export

#### 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 Controls_ panel when in Paint mode.
The menu options are available in the _Image_ menu, as well as in the context
menu of a texture or layer, and in the Layers panel.

#### 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.

#### Finding Assigned Channels

Select a texture with material layers assigned to reveal the _PBR Channels_
panel. This panel displays the channels currently assigned in the selected
texture. Click a channel in the menu to have it selected in the Layers panel.

### Material Brush Tool

Use the _Material Brush Tool_ to paint across multiple PBR channels. The
controls found in the _Material Brush Panel_.

- Set the metallic, roughness and height values on a scale of 0% - 100%
- Use the color picker in the _Material Brush Panel_ to set the emissive color.
- The current color selected in the main color picker is used as the albedo
color.
- Only visible layers with channels assigned will be updated by the brush.
- Blockbench's paint brush size and smoothness settings control the material
brush's settings as well.

#### Material Brush Presets

Open the _Material Brush Presets_ dialog to define and save new brush settings,
or to select and apply existing presets. A material preview is generated upon
saving a preset. Select a preset to populate its values in the Material Brush
input controls.

### `.bbmat` Files
- Import Blockbench PBR materials by dropping a `.bbmat` file into a Blockbench project.
- The import option is also available in the _File_ menu.
- Export existing materials from texture content menu to save its assigned channels together in one file.
51 changes: 51 additions & 0 deletions plugins/pbr_preview/changelog.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
{
"1.0.0": {
"title": "1.0.0",
"date": "2024-05-25",
"author": "Jason J. Gardner",
"categories": [
{
"title": "PBR plugin",
"list": [
"Initial release 🚀"
]
}
]
},
"1.1.0": {
"title": "1.1.0",
"date": "2024-06-10",
"author": "Jason J. Gardner",
"categories": [
{
"title": "Java Support",
"list": [
"Added labPBR export option",
"Added labPBR texture decoding"
]
},
{
"title": "Material Brush",
"list": [
"Added material brush tool",
"Added material brush preset dialog"
]
}
]
},
"1.2.0": {
"title": "1.2.0",
"date": "2024-06-20",
"author": "Jason J. Gardner",
"categories": [
{
"title": "USDZ Export",
"list": [
"Added USDZ export option",
"Added normal map orientation options",
"Created `.bbmat` codec"
]
}
]
}
}
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
291 changes: 291 additions & 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
12 changes: 12 additions & 0 deletions src/pbr_preview/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"semi": true,
"trailingComma": "es5",
"singleQuote": false,
"printWidth": 80,
"tabWidth": 2,
"vueIndentScriptAndStyle": true,
"bracketSameLine": false,
"arrowParens": "always",
"endOfLine": "lf",
"quoteProps": "as-needed"
}
Loading
Loading