Skip to content

Commit

Permalink
remove anamorphic bloom feature
Browse files Browse the repository at this point in the history
This features didn't work well, had a lot of artifacts and generally
wasn't very useful. This kind of effect should be accomplished
differently.

This is an API break because BloomOptions::anamorphism has been removed.
  • Loading branch information
pixelflinger committed Sep 18, 2023
1 parent 13df665 commit 9474798
Show file tree
Hide file tree
Showing 22 changed files with 27 additions and 65 deletions.
2 changes: 2 additions & 0 deletions NEW_RELEASE_NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ for next branch cut* header.
appropriate header in [RELEASE_NOTES.md](./RELEASE_NOTES.md).

## Release notes for next branch cut

- engine: remove `BloomOptions::anamorphism` which wasn't working well in most cases [**API CHANGE**]
3 changes: 1 addition & 2 deletions android/filament-android/src/main/cpp/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ Java_com_google_android_filament_View_nSetSSCTOptions(JNIEnv *, jclass, jlong na
extern "C" JNIEXPORT void JNICALL
Java_com_google_android_filament_View_nSetBloomOptions(JNIEnv*, jclass,
jlong nativeView, jlong nativeTexture,
jfloat dirtStrength, jfloat strength, jint resolution, jfloat anamorphism, jint levels,
jfloat dirtStrength, jfloat strength, jint resolution, jint levels,
jint blendMode, jboolean threshold, jboolean enabled, jfloat highlight,
jboolean lensFlare, jboolean starburst, jfloat chromaticAberration, jint ghostCount,
jfloat ghostSpacing, jfloat ghostThreshold, jfloat haloThickness, jfloat haloRadius,
Expand All @@ -294,7 +294,6 @@ Java_com_google_android_filament_View_nSetBloomOptions(JNIEnv*, jclass,
.dirtStrength = dirtStrength,
.strength = strength,
.resolution = (uint32_t)resolution,
.anamorphism = anamorphism,
.levels = (uint8_t)levels,
.blendMode = (View::BloomOptions::BlendMode)blendMode,
.threshold = (bool)threshold,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -904,7 +904,7 @@ public void setBloomOptions(@NonNull BloomOptions options) {
mBloomOptions = options;
nSetBloomOptions(getNativeObject(), options.dirt != null ? options.dirt.getNativeObject() : 0,
options.dirtStrength, options.strength, options.resolution,
options.anamorphism, options.levels, options.blendMode.ordinal(),
options.levels, options.blendMode.ordinal(),
options.threshold, options.enabled, options.highlight,
options.lensFlare, options.starburst, options.chromaticAberration,
options.ghostCount, options.ghostSpacing, options.ghostThreshold,
Expand Down Expand Up @@ -1216,7 +1216,7 @@ void clearNativeObject() {
private static native int nGetAmbientOcclusion(long nativeView);
private static native void nSetAmbientOcclusionOptions(long nativeView, float radius, float bias, float power, float resolution, float intensity, float bilateralThreshold, int quality, int lowPassFilter, int upsampling, boolean enabled, boolean bentNormals, float minHorizonAngleRad);
private static native void nSetSSCTOptions(long nativeView, float ssctLightConeRad, float ssctStartTraceDistance, float ssctContactDistanceMax, float ssctIntensity, float v, float v1, float v2, float ssctDepthBias, float ssctDepthSlopeBias, int ssctSampleCount, int ssctRayCount, boolean ssctEnabled);
private static native void nSetBloomOptions(long nativeView, long dirtNativeObject, float dirtStrength, float strength, int resolution, float anamorphism, int levels, int blendMode, boolean threshold, boolean enabled, float highlight,
private static native void nSetBloomOptions(long nativeView, long dirtNativeObject, float dirtStrength, float strength, int resolution, int levels, int blendMode, boolean threshold, boolean enabled, float highlight,
boolean lensFlare, boolean starburst, float chromaticAberration, int ghostCount, float ghostSpacing, float ghostThreshold, float haloThickness, float haloRadius, float haloThreshold);
private static native void nSetFogOptions(long nativeView, float distance, float maximumOpacity, float height, float heightFalloff, float cutOffDistance, float v, float v1, float v2, float density, float inScatteringStart, float inScatteringSize, boolean fogColorFromIbl, long skyColorNativeObject, boolean enabled);
private static native void nSetBlendMode(long nativeView, int blendMode);
Expand Down Expand Up @@ -1353,8 +1353,6 @@ public static class DynamicResolutionOptions {
* blendMode: Whether the bloom effect is purely additive (false) or mixed with the original
* image (true).
*
* anamorphism: Bloom's aspect ratio (x/y), for artistic purposes.
*
* threshold: When enabled, a threshold at 1.0 is applied on the source image, this is
* useful for artistic reasons and is usually needed when a dirt texture is used.
*
Expand Down Expand Up @@ -1393,10 +1391,6 @@ public enum BlendMode {
* resolution of vertical axis (2^levels to 2048)
*/
public int resolution = 384;
/**
* bloom x/y aspect-ratio (1/32 to 32)
*/
public float anamorphism = 1.0f;
/**
* number of blur levels (1 to 11)
*/
Expand Down
4 changes: 2 additions & 2 deletions docs/remote/filament.js

Large diffs are not rendered by default.

Binary file modified docs/remote/filament.wasm
Binary file not shown.
4 changes: 2 additions & 2 deletions docs/webgl/filament.js

Large diffs are not rendered by default.

Binary file modified docs/webgl/filament.wasm
Binary file not shown.
Binary file modified docs/webgl/parquet.filamat
Binary file not shown.
Binary file modified docs/webgl/plastic.filamat
Binary file not shown.
Binary file modified docs/webgl/textured.filamat
Binary file not shown.
Binary file modified docs/webgl/triangle.filamat
Binary file not shown.
27 changes: 13 additions & 14 deletions docs/webgl/tutorial_suzanne.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,27 +22,26 @@ <h2>Create mipmapped textures</h2>
<p>Next, let&#x27;s create mipmapped KTX files using filament&#x27;s <code>mipgen</code> tool. We&#x27;ll create compressed and
non-compressed variants for each texture, since not all platforms support the same compression
formats. First copy over the PNG files from the <a href="https://github.com/google/filament/blob/main/assets/models/monkey">monkey folder</a>, then do:</p>
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic"># Create mipmaps for base color and two compressed variants.</span>
mipgen albedo.png albedo.ktx
mipgen --compression<span style="color: #666666">=</span>astc_fast_ldr_4x4 albedo.png albedo_astc.ktx
mipgen --compression<span style="color: #666666">=</span>s3tc_rgb_dxt1 albedo.png albedo_s3tc_srgb.ktx
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span><span style="color: #3D7B7B; font-style: italic"># Create mipmaps for base color</span>
mipgen albedo.png albedo.ktx2
mipgen --compression<span style="color: #666666">=</span>uastc albedo.png albedo.ktx2

<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the normal map and a compressed variant.</span>
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear normal.png normal.ktx
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear --compression<span style="color: #666666">=</span>etc_rgb8_normalxyz_40 <span style="color: #AA5D1F; font-weight: bold">\</span>
normal.png normal_etc.ktx
mipgen --strip-alpha --kernel<span style="color: #666666">=</span>NORMALS --linear --compression<span style="color: #666666">=</span>uastc_normals <span style="color: #AA5D1F; font-weight: bold">\</span>
normal.png normal.ktx2

<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component roughness map and a compressed variant.</span>
mipgen --grayscale roughness.png roughness.ktx
mipgen --grayscale --compression<span style="color: #666666">=</span>etc_r11_numeric_40 roughness.png roughness_etc.ktx
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc roughness.png roughness.ktx2

<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component metallic map and a compressed variant.</span>
mipgen --grayscale metallic.png metallic.ktx
mipgen --grayscale --compression<span style="color: #666666">=</span>etc_r11_numeric_40 metallic.png metallic_etc.ktx
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc metallic.png metallic.ktx2

<span style="color: #3D7B7B; font-style: italic"># Create mipmaps for the single-component occlusion map and a compressed variant.</span>
mipgen --grayscale ao.png ao.ktx
mipgen --grayscale --compression<span style="color: #666666">=</span>etc_r11_numeric_40 ao.png ao_etc.ktx
mipgen --grayscale --compression<span style="color: #666666">=</span>uastc ao.png ao.ktx2
</pre></div>

<p>For more information on mipgen&#x27;s arguments and supported formats, do <code>mipgen --help</code>.</p>
Expand Down Expand Up @@ -207,11 +206,11 @@ <h2>Fetch assets asychronously</h2>
recreate the skybox using a higher-resolution texture. As a last step we unhide the renderable that
was created in the app constructor.</p>
<div class="highlight" style="background: #f8f8f8"><pre style="line-height: 125%;"><span></span>Filament.fetch([sky_large_url,<span style="color: #bbbbbb"> </span>albedo_url,<span style="color: #bbbbbb"> </span>roughness_url,<span style="color: #bbbbbb"> </span>metallic_url,<span style="color: #bbbbbb"> </span>normal_url,<span style="color: #bbbbbb"> </span>ao_url],<span style="color: #bbbbbb"> </span>()<span style="color: #bbbbbb"> </span>=&gt;<span style="color: #bbbbbb"> </span>{<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx1(albedo_url,<span style="color: #bbbbbb"> </span>{srgb<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">true</span>});<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>roughness<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx1(roughness_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>metallic<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx1(metallic_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>normal<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx1(normal_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ao<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx1(ao_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>albedo<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(albedo_url,<span style="color: #bbbbbb"> </span>{srgb<span style="color: #666666">:</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">true</span>});<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>roughness<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(roughness_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>metallic<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(metallic_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>normal<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(normal_url);<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>ao<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">this</span>.engine.createTextureFromKtx2(ao_url);<span style="color: #bbbbbb"></span>

<span style="color: #bbbbbb"> </span><span style="color: #008000; font-weight: bold">const</span><span style="color: #bbbbbb"> </span>sampler<span style="color: #bbbbbb"> </span><span style="color: #666666">=</span><span style="color: #bbbbbb"> </span><span style="color: #AA22FF; font-weight: bold">new</span><span style="color: #bbbbbb"> </span>Filament.TextureSampler(<span style="color: #bbbbbb"></span>
<span style="color: #bbbbbb"> </span>Filament.MinFilter.LINEAR_MIPMAP_LINEAR,<span style="color: #bbbbbb"></span>
Expand Down
10 changes: 5 additions & 5 deletions docs/webgl/tutorial_suzanne.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,13 @@ class App {
});
Filament.fetch([sky_large_url, albedo_url, roughness_url, metallic_url, normal_url, ao_url],
() => {
const albedo = this.engine.createTextureFromKtx1(albedo_url, {
const albedo = this.engine.createTextureFromKtx2(albedo_url, {
srgb: true
});
const roughness = this.engine.createTextureFromKtx1(roughness_url);
const metallic = this.engine.createTextureFromKtx1(metallic_url);
const normal = this.engine.createTextureFromKtx1(normal_url);
const ao = this.engine.createTextureFromKtx1(ao_url);
const roughness = this.engine.createTextureFromKtx2(roughness_url);
const metallic = this.engine.createTextureFromKtx2(metallic_url);
const normal = this.engine.createTextureFromKtx2(normal_url);
const ao = this.engine.createTextureFromKtx2(ao_url);
const sampler = new Filament.TextureSampler(Filament.MinFilter.LINEAR_MIPMAP_LINEAR,
Filament.MagFilter.LINEAR, Filament.WrapMode.CLAMP_TO_EDGE);
this.matinstance.setTextureParameter('albedo', albedo, sampler);
Expand Down
3 changes: 0 additions & 3 deletions filament/include/filament/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,6 @@ struct DynamicResolutionOptions {
* blendMode: Whether the bloom effect is purely additive (false) or mixed with the original
* image (true).
*
* anamorphism: Bloom's aspect ratio (x/y), for artistic purposes.
*
* threshold: When enabled, a threshold at 1.0 is applied on the source image, this is
* useful for artistic reasons and is usually needed when a dirt texture is used.
*
Expand All @@ -134,7 +132,6 @@ struct BloomOptions {
float dirtStrength = 0.2f; //!< strength of the dirt texture %codegen_skip_json% %codegen_skip_javascript%
float strength = 0.10f; //!< bloom's strength between 0.0 and 1.0
uint32_t resolution = 384; //!< resolution of vertical axis (2^levels to 2048)
float anamorphism = 1.0f; //!< bloom x/y aspect-ratio (1/32 to 32)
uint8_t levels = 6; //!< number of blur levels (1 to 11)
BlendMode blendMode = BlendMode::ADD; //!< how the bloom effect is applied
bool threshold = true; //!< whether to threshold the source
Expand Down
10 changes: 0 additions & 10 deletions filament/src/PostProcessManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1921,16 +1921,6 @@ PostProcessManager::BloomPassOutput PostProcessManager::bloomPass(FrameGraph& fg
float bloomHeight = float(inoutBloomOptions.resolution);
float bloomWidth = bloomHeight * aspect;

// Anamorphic bloom by always scaling down one of the dimension -- we do this (as opposed
// to scaling up) so that the amount of blooming doesn't decrease. However, the resolution
// decreases, meaning that the user might need to adjust the BloomOptions::resolution and
// BloomOptions::levels.
if (inoutBloomOptions.anamorphism >= 1.0f) {
bloomWidth *= 1.0f / inoutBloomOptions.anamorphism;
} else {
bloomHeight *= inoutBloomOptions.anamorphism;
}

// we might need to adjust the max # of levels
const uint32_t major = uint32_t(std::max(bloomWidth, bloomHeight));
const uint8_t maxLevels = FTexture::maxLevelCount(major);
Expand Down
1 change: 0 additions & 1 deletion filament/src/details/View.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1083,7 +1083,6 @@ void FView::setBloomOptions(BloomOptions options) noexcept {
options.resolution = math::clamp(options.resolution, 2u, 2048u);
options.levels = math::clamp(options.levels, uint8_t(1),
FTexture::maxLevelCount(options.resolution));
options.anamorphism = math::clamp(options.anamorphism, 1.0f/32.0f, 32.0f);
options.highlight = std::max(10.0f, options.highlight);
mBloomOptions = options;
}
Expand Down
3 changes: 0 additions & 3 deletions libs/viewer/src/Settings_generated.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -237,8 +237,6 @@ int parse(jsmntok_t const* tokens, int i, const char* jsonChunk, BloomOptions* o
i = parse(tokens, i + 1, jsonChunk, &out->strength);
} else if (compare(tok, jsonChunk, "resolution") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->resolution);
} else if (compare(tok, jsonChunk, "anamorphism") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->anamorphism);
} else if (compare(tok, jsonChunk, "levels") == 0) {
i = parse(tokens, i + 1, jsonChunk, &out->levels);
} else if (compare(tok, jsonChunk, "blendMode") == 0) {
Expand Down Expand Up @@ -287,7 +285,6 @@ std::ostream& operator<<(std::ostream& out, const BloomOptions& in) {
// JSON serialization for dirtStrength is not supported.
<< "\"strength\": " << (in.strength) << ",\n"
<< "\"resolution\": " << (in.resolution) << ",\n"
<< "\"anamorphism\": " << (in.anamorphism) << ",\n"
<< "\"levels\": " << int(in.levels) << ",\n"
<< "\"blendMode\": " << (in.blendMode) << ",\n"
<< "\"threshold\": " << to_string(in.threshold) << ",\n"
Expand Down
6 changes: 0 additions & 6 deletions libs/viewer/src/ViewerGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,12 +767,6 @@ void ViewerGui::updateUserInterface() {
ImGui::SliderFloat("Strength", &mSettings.view.bloom.strength, 0.0f, 1.0f);
ImGui::Checkbox("Threshold", &mSettings.view.bloom.threshold);

float anamorphism = mSettings.view.bloom.anamorphism >= 1.0f ?
mSettings.view.bloom.anamorphism - 1.0f : 1.0f - 1.0f / mSettings.view.bloom.anamorphism;
ImGui::SliderFloat("Amamorphism", &anamorphism, -32.0f, 32.0f);
mSettings.view.bloom.anamorphism = anamorphism >= 0 ?
(anamorphism + 1.0f) : 1.0f / (1.0f - anamorphism);

int levels = mSettings.view.bloom.levels;
ImGui::SliderInt("Levels", &levels, 3, 11);
mSettings.view.bloom.levels = levels;
Expand Down
1 change: 0 additions & 1 deletion libs/viewer/tests/test_settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,6 @@ static const char* JSON_TEST_DEFAULTS = R"TXT(
"enabled": false,
"strength": 0.10,
"resolution": 360,
"anamorphism": 1.0,
"levels": 6,
"blendMode": "ADD",
"threshold": true,
Expand Down
1 change: 0 additions & 1 deletion web/filament-js/extensions_generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ Filament.loadGeneratedExtensions = function() {
// JavaScript binding for dirtStrength is not yet supported, must use default value.
strength: 0.10,
resolution: 384,
anamorphism: 1.0,
levels: 6,
blendMode: Filament.View$BloomOptions$BlendMode.ADD,
threshold: true,
Expand Down
6 changes: 0 additions & 6 deletions web/filament-js/filament.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1207,8 +1207,6 @@ export enum View$BloomOptions$BlendMode {
* blendMode: Whether the bloom effect is purely additive (false) or mixed with the original
* image (true).
*
* anamorphism: Bloom's aspect ratio (x/y), for artistic purposes.
*
* threshold: When enabled, a threshold at 1.0 is applied on the source image, this is
* useful for artistic reasons and is usually needed when a dirt texture is used.
*
Expand All @@ -1229,10 +1227,6 @@ export interface View$BloomOptions {
* resolution of vertical axis (2^levels to 2048)
*/
resolution?: number;
/**
* bloom x/y aspect-ratio (1/32 to 32)
*/
anamorphism?: number;
/**
* number of blur levels (1 to 11)
*/
Expand Down
Loading

0 comments on commit 9474798

Please sign in to comment.