-
Notifications
You must be signed in to change notification settings - Fork 193
Added Mr Salmon's Baked Ambient Occlusion #757
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
Open
kaisalmon
wants to merge
4
commits into
JannisX11:master
Choose a base branch
from
kaisalmon:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| MIT License | ||
|
|
||
| Copyright (c) 2025 Kai Salmon | ||
|
|
||
| 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. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Mr Salmon's Baked Ambient Occlusion for Blockbench | ||
|
|
||
| Generate instant shaded textures for your models, with one click! Ambient occlusion works by working out how much light can reach each pixel on the model: areas in crevices and divots receive less light than those at the edge of the model. By exaggerating this effect, you can create depth, as crevices also often pick up dirt, becoming even darker, and the edges of hard objects (like rocks, wood, metal, etc.) often get worn, becoming even lighter. | ||
|
|
||
| *Before* | ||
|  | ||
|
|
||
| *After* | ||
|  | ||
|
|
||
| ## Building and installing. | ||
|
|
||
| To install clone the repo, and run `npm install` and then `npm build`. This will create a file at `dist\blockbench-baked-ao.js`. In Blockbench, you can then go to plugins, and select "load from file", and select the file you just created. | ||
|
|
||
| ## Using the plugin | ||
|
|
||
| Select your mesh, and go to Tools > Bake Ambient Occlusion | ||
|
|
||
| <img width="366" height="240" alt="image" src="https://github.com/user-attachments/assets/d43d35cb-b9e1-41ef-afa6-dbd9d960bd8e" /> | ||
|
|
||
|
|
||
| ## Settings | ||
| <img width="491" height="691" alt="image" src="https://github.com/user-attachments/assets/ba7175f1-db3d-4819-8847-5563d741502b" /> | ||
|
|
||
| ### **Highlight Color** | ||
| Color used for areas with high ambient lighting | ||
|
|
||
| ### **Highlight Opacity** | ||
| Opacity of the highlight color overlay | ||
|
|
||
| ### **Highlight Gamma** | ||
| Gamma correction for highlight areas (lower = more contrast) | ||
|
|
||
| ### **Shadow Color** | ||
| Color used for occluded/shadowed areas | ||
|
|
||
| ### **Shadow Opacity** | ||
| Opacity of the shadow color overlay | ||
|
|
||
| ### **Shadow Gamma** | ||
| Gamma correction for shadow areas (higher = softer shadows) | ||
|
|
||
| ### **Samples per pixel** | ||
| Number of samples per pixel (higher = better quality, slower). 100 recommended for uniform sampling, 1000 for random sampling. | ||
|
|
||
| ### **Sample Method** | ||
| Method for sampling ambient occlusion rays. Random is slightly more accurate but noisier, uniform is smoother for less samples but is more prone to artifacts. | ||
|
|
||
| ### **Ambient Occlusion Radius** | ||
| Radius for ambient occlusion effect (Bigger is better for larger models or higher-resolution textures) | ||
|
|
||
| ### **Simulate Ground Plane** | ||
| Simulate a ground plane, adding shadows at the base of the model | ||
|
|
||
| ### **Retain Texture Transparency** | ||
| Preserve the original transparency of textures | ||
|
|
||
| ### **Sample Texture Transparency** | ||
| Consider texture transparency when calculating occlusion (slower but more accurate) | ||
|
|
||
| # Credit and Acknowledgments | ||
|
|
||
| Code by Kai Salmon. | ||
|
|
||
| Massive performance gains were achieved by using [ThreeJS Bounding Volume Heiarachies | ||
| ](https://github.com/gkjohnson/three-mesh-bvh) by Garrett Johnson. | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,82 @@ | ||
| # Mr Salmon's Baked Ambient Occlusion | ||
|
|
||
| Generate instant shaded textures for your models with one click! This plugin bakes ambient occlusion directly onto your mesh textures by calculating how much ambient light can reach each pixel on the model. Ambient, in this context, means "equally from-all directions". Areas in crevices and divots receive less light than those at the edges, creating natural depth and shading effects. Pixels on the sharp edge of models recieve more light, so are highlighted. | ||
|
|
||
| To use this plugin, select a mesh and go to `Tools > Bake Ambient Occlusion`. Configure your settings in the dialog and click `Confirm` to start the baking process. | ||
|
|
||
| ## How Ambient Occlusion Works | ||
|
|
||
| Ambient occlusion works by casting rays from each pixel on your model's surface to determine how much ambient light can reach that point. Areas that are occluded by nearby geometry (like crevices, corners, and recessed areas) receive less light and appear darker, while exposed edges and surfaces remain bright. By exaggerating this effect, you can even simulate how dirt accumulates in crevices and how edges of hard materials like rocks, wood, and metal get worn and lightened over time. | ||
|
|
||
| ## Settings Reference | ||
|
|
||
| ### Colors and Opacity | ||
|
|
||
|  | ||
|  | ||
| **Highlight Color & Opacity**: Sets the color and transparency used for well-lit, exposed areas of your model. These areas typically represent worn edges or surfaces that receive full ambient lighting. | ||
|
|
||
| **Shadow Color & Opacity**: Sets the color and transparency used for occluded, shadowed areas. These areas represent crevices, corners, and recessed surfaces where dirt and grime would naturally accumulate. | ||
|
|
||
| ### Gamma Correction | ||
|
|
||
|  | ||
|
|
||
| **Highlight Gamma**: Controls the contrast and falloff of highlight areas. Lower values create more dramatic contrast with sharper transitions, while higher values create softer, more gradual highlights. | ||
|
|
||
| **Shadow Gamma**: Controls the contrast and falloff of shadow areas. Higher values create softer, more subtle shadows, while lower values create harder, more defined shadows. | ||
|
|
||
| ### AO Strength and Quality | ||
|
|
||
| **Samples per pixel**: Determines the quality and accuracy of the ambient occlusion calculation. Higher values produce smoother, more accurate results but take longer to process. Recommended values: | ||
| - 100-500 samples for quick previews, or when using uniform sampling. | ||
| - 1000+ samples for final quality results | ||
|
|
||
| **Sample Method**: Choose between sampling methods: | ||
| - **Random**: Slightly more accurate but can be noisier, especially with fewer samples. Of course, noise can be desirable! | ||
| - **Uniform**: Produces smoother results with fewer samples but may show artifacts in some cases, especailly with low samples. | ||
|
|
||
| ### Occlusion Radius | ||
|
|
||
|  | ||
|
|
||
| **Ambient Occlusion Radius (Pixels)**: Controls how far the occlusion effect extends from each surface. Larger values create larger shadows that affect more distant geometry, while smaller values create tighter, more localized effects. Use larger values for bigger models or higher-resolution textures. | ||
|
|
||
| ### Ground Plane Simulation | ||
|
|
||
|  | ||
|
|
||
| **Simulate Ground Plane**: Allows the ground beneath your model to occlude light. This creates natural contact shadows at the base of your model, making it appear more grounded. | ||
|
|
||
| ### Transparency Handling | ||
|
|
||
|  | ||
|
|
||
| **Retain Texture Transparency**: Preserves the original alpha channel of your textures. When enabled, the ambient occlusion effect will respect existing transparent areas and not overwrite them completely. | ||
|
|
||
| **Sample Texture Transparency**: Makes the occlusion calculation consider the transparency of textures when casting rays. Semi-transparent areas will allow some light to pass through rather than casting complete shadows. This produces more accurate results in models with a lot of transparent pixels but increases processing time significantly. | ||
|
|
||
| ## Usage Tips | ||
|
|
||
| ### Getting Started | ||
| 1. Select the mesh you want to process (only one mesh at a time is supported) | ||
| 2. Go to `Tools > Bake Ambient Occlusion` | ||
| 3. Adjust settings based on your model size and desired effect | ||
| 4. Click `Confirm` to start baking | ||
|
|
||
| ### Recommended Settings | ||
| - **For quick previews**: 100-200 samples, uniform sampling | ||
| - **For final results**: 1000+ samples, random sampling | ||
| - **For large models**: Increase ambient occlusion radius to 12-16 | ||
| - **For detailed textures**: Use higher sample counts and enable texture transparency sampling | ||
|
|
||
| # Credit and Acknowledgments | ||
|
|
||
| Plugin by Kai Salmon. | ||
|
|
||
| Massive performance gains were achieved by using [ThreeJS Bounding Volume Heiarachies | ||
| ](https://github.com/gkjohnson/three-mesh-bvh) by Garrett Johnson. | ||
|
|
||
| # Source code and Contributions | ||
|
|
||
| You can contribute to the code and report any issues on [github](https://github.com/kaisalmon/MrsSalmonsBlockbenchBakedAmbientOcclusion/blob/main/about.md). | ||
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| { | ||
| "name": "blockbench-baked-ao", | ||
| "version": "1.0.0", | ||
| "description": "Baked Ambient Occlusion for Blockbench", | ||
| "main": "dist/index.js", | ||
| "scripts": { | ||
| "build": "webpack --mode production", | ||
| "dev": "webpack --mode development", | ||
| "watch": "webpack --mode development --watch" | ||
| }, | ||
| "devDependencies": { | ||
| "@types/three": "^0.160.0", | ||
| "blockbench-types": "^4.12.2", | ||
| "ts-loader": "^9.5.1", | ||
| "typescript": "^5.3.3", | ||
| "webpack": "^5.89.0", | ||
| "webpack-cli": "^5.1.4" | ||
| }, | ||
| "dependencies": { | ||
| "three": "^0.160.0", | ||
| "three-mesh-bvh": "^0.9.1" | ||
| } | ||
| } |
Binary file added
BIN
+137 KB
plugins/baked_ambient_occlusion/settings_reference_guides/ao_strength.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+34.4 KB
plugins/baked_ambient_occlusion/settings_reference_guides/ground_plane.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+102 KB
plugins/baked_ambient_occlusion/settings_reference_guides/sampling.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+71.2 KB
plugins/baked_ambient_occlusion/settings_reference_guides/transparency.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@JannisX11 Do you know if this image link is correctly configured to work within Blockbench?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, Blockbench doesn't handle images that are part of plugins. You will need to link to a full web address where the image is hosted, you can look at the mesh_tools plugin for example as a reference.