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

Fix background blur with 0 steps #15

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ interface RenderingOptions
/**
* Background blur steps used for background & raindrop refract image.
* Value should be integer from 0 to log2(backgroundSize).
* Set to 0 will not blur the background image.
* Recommend 3 or 4
*/
backgroundBlurSteps: number,
Expand All @@ -283,7 +284,8 @@ interface RenderingOptions
/**
* Background blur steps used for mist.
* Value should be integer from 0 to log2(backgroundSize).
* Recommended value = backgroundBlurSteps + 1
* Recommended value = backgroundBlurSteps + 1.
* Set to 0 will disable mist blur.
*/
mistBlurStep: number,
/**
Expand Down
4 changes: 2 additions & 2 deletions bundle/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions bundle/index.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/blur.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export declare class BlurRenderer {
mateiralBlur: MaterialBlur;
constructor(renderer: ZograRenderer);
init(texture: Texture): void;
blur(texture: Texture, iteration?: number, output?: RenderTexture): RenderTexture;
blur(texture: Texture, iteration?: number, output?: RenderTexture): RenderTexture | undefined;
downSample(input: Texture, iteration: number): void;
upSample(iteration: number, finalOutput?: RenderTexture): RenderTexture;
}
Expand Down
2 changes: 1 addition & 1 deletion dist/blur.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/index.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions dist/index.js.map

Large diffs are not rendered by default.

4 changes: 3 additions & 1 deletion dist/renderer.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export interface RenderOptions {
/**
* Background blur steps used for background & raindrop refract image.
* Value should be integer from 0 to log2(backgroundSize).
* Set to 0 will disable background blur.
* Recommend 3 or 4
*/
backgroundBlurSteps: number;
Expand All @@ -33,7 +34,8 @@ export interface RenderOptions {
/**
* Background blur steps used for mist.
* Value should be integer from 0 to log2(backgroundSize).
* Recommended value = backgroundBlurSteps + 1
* Recommended value = backgroundBlurSteps + 1.
* Set to 0 will disable mist blur.
*/
mistBlurStep: number;
/**
Expand Down
2 changes: 1 addition & 1 deletion dist/renderer.d.ts.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "raindrop-fx",
"version": "1.0.8",
"version": "1.0.9",
"description": "Rain drop effect with WebGL",
"main": "dist/index.js",
"scripts": {
Expand Down
6 changes: 6 additions & 0 deletions src/blur.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ export class BlurRenderer
if (this.steps[0].width !== texture.width || this.steps[0].height !== texture.height)
this.steps[0].resize(texture.width, texture.height, TextureResizing.Discard);

if (iteration == 0)
{
this.renderer.blit(texture, output);
return;
}

this.downSample(texture, iteration);

return this.upSample(iteration, output);
Expand Down
9 changes: 8 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ export interface RenderOptions
/**
* Background blur steps used for background & raindrop refract image.
* Value should be integer from 0 to log2(backgroundSize).
* Set to 0 will disable background blur.
* Recommend 3 or 4
*/
backgroundBlurSteps: number;
Expand All @@ -165,7 +166,8 @@ export interface RenderOptions
/**
* Background blur steps used for mist.
* Value should be integer from 0 to log2(backgroundSize).
* Recommended value = backgroundBlurSteps + 1
* Recommended value = backgroundBlurSteps + 1.
* Set to 0 will disable mist blur.
*/
mistBlurStep: number;
/**
Expand Down Expand Up @@ -397,6 +399,11 @@ export class RaindropRenderer
}
else
{
if (this.options.backgroundBlurSteps == 0)
{
this.blurryBackground = this.background;
}

// Downsample to max steps
// Then upsample from a larger texture before smaller texture to avoid override
this.blurRenderer.init(this.background);
Expand Down