Skip to content

Commit

Permalink
Add SMAAEffect (#608)
Browse files Browse the repository at this point in the history
* Implement SMAAEffect

* Fix test

* Update SMAAEffect.ts

* Update smaa.ts

* Update SMAAEdgeDetectionMaterial.ts
  • Loading branch information
vanruesc authored Mar 1, 2024
1 parent 31108b1 commit 61f2445
Show file tree
Hide file tree
Showing 17 changed files with 515 additions and 72 deletions.
64 changes: 33 additions & 31 deletions manual/assets/js/src/demos/smaa.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,16 @@ import {

import {
ClearPass,
EffectPass,
GeometryPass,
RenderPipeline
MixBlendFunction,
RenderPipeline,
SMAAEdgeDetectionMode,
SMAAPredicationMode,
SMAAEffect,
SMAAPreset,
TextureEffect,
ToneMappingEffect
} from "postprocessing";

import { Pane } from "tweakpane";
Expand Down Expand Up @@ -84,30 +92,25 @@ window.addEventListener("load", () => void load().then((assets) => {

// Post Processing

const effect = new SMAAEffect({
preset: SMAAPreset.MEDIUM,
edgeDetectionMode: SMAAEdgeDetectionMode.COLOR,
predicationMode: SMAAPredicationMode.DEPTH
});

const effectPass = new EffectPass(effect, new ToneMappingEffect());

const pipeline = new RenderPipeline(renderer);
pipeline.autoRenderToScreen = false;

pipeline.add(
new ClearPass(),
new GeometryPass(scene, camera, {
frameBufferType: HalfFloatType
})
}),
effectPass
);

/*
const effect = new SMAAEffect({
blendFunction: BlendFunction.NORMAL,
preset: SMAAPreset.MEDIUM,
edgeDetectionMode: EdgeDetectionMode.COLOR,
predicationMode: PredicationMode.DEPTH
});
const edgeDetectionMaterial = effect.edgeDetectionMaterial;
edgeDetectionMaterial.edgeDetectionThreshold = 0.02;
edgeDetectionMaterial.predicationThreshold = 0.002;
edgeDetectionMaterial.predicationScale = 1;
const effectPass = new EffectPass(effect, new ToneMappingEffect());
// #region DEBUG
const smaaEdgesDebugPass = new EffectPass(effect, new TextureEffect({ texture: effect.edgesTexture }));
const smaaWeightsDebugPass = new EffectPass(effect, new TextureEffect({ texture: effect.weightsTexture }));
Expand All @@ -118,21 +121,18 @@ window.addEventListener("load", () => void load().then((assets) => {
smaaWeightsDebugPass.output.defaultBuffer = null;
smaaEdgesDebugPass.enabled = false;
smaaWeightsDebugPass.enabled = false;
smaaEdgesDebugPass.fullscreenMaterial.encodeOutput = false;
smaaWeightsDebugPass.fullscreenMaterial.encodeOutput = false;
// #endregion DEBUG
smaaEdgesDebugPass.fullscreenMaterial.colorSpaceConversion = false;
smaaWeightsDebugPass.fullscreenMaterial.colorSpaceConversion = false;

pipeline.addPass(effectPass);
pipeline.addPass(smaaEdgesDebugPass);
pipeline.addPass(smaaWeightsDebugPass);
*/
pipeline.add(smaaEdgesDebugPass, smaaWeightsDebugPass);
// #endregion DEBUG

// Settings

const pane = new Pane({ container: container.querySelector(".tp") as HTMLElement });
const fpsGraph = Utils.createFPSGraph(pane);
const edgeDetectionMaterial = effect.edgeDetectionMaterial;

/*
const smaaDebug = {
OFF: 0,
EDGES: 1,
Expand Down Expand Up @@ -161,16 +161,18 @@ window.addEventListener("load", () => void load().then((assets) => {

});

const edgeDetectionOptions = Utils.enumToRecord(SMAAEdgeDetectionMode);
const predicationOptions = Utils.enumToRecord(SMAAPredicationMode);

const subfolder = folder.addFolder({ title: "Edge Detection", expanded: false });
subfolder.addBinding(edgeDetectionMaterial, "edgeDetectionMode", { options: Utils.enumToRecord(EdgeDetectionMode) });
subfolder.addBinding(edgeDetectionMaterial, "edgeDetectionThreshold", { min: 0.01, max: 0.3, step: 1e-4 });
subfolder.addBinding(edgeDetectionMaterial, "predicationMode", { options: Utils.enumToRecord(PredicationMode) });
subfolder.addBinding(edgeDetectionMaterial, "predicationThreshold", { min: 4e-4, max: 0.01, step: 1e-4 });
subfolder.addBinding(edgeDetectionMaterial, "edgeDetectionMode", { options: edgeDetectionOptions });
subfolder.addBinding(edgeDetectionMaterial, "edgeDetectionThreshold", { min: 1e-5, max: 0.1, step: 1e-5 });
subfolder.addBinding(edgeDetectionMaterial, "predicationMode", { options: predicationOptions });
subfolder.addBinding(edgeDetectionMaterial, "predicationThreshold", { min: 1e-4, max: 0.01, step: 1e-4 });
subfolder.addBinding(edgeDetectionMaterial, "predicationStrength", { min: 0, max: 1, step: 1e-4 });
subfolder.addBinding(edgeDetectionMaterial, "predicationScale", { min: 1, max: 2, step: 0.01 });
subfolder.addBinding(edgeDetectionMaterial, "predicationScale", { min: 1, max: 5, step: 0.01 });

Utils.addBlendModeBindings(folder, effect.blendMode);
*/

// Resize Handler

Expand Down
2 changes: 1 addition & 1 deletion manual/content/demos/anti-aliasing/smaa.en.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
layout: single
collection: sections
title: SMAA
draft: true
draft: false
menu:
demos:
parent: anti-aliasing
Expand Down
Loading

0 comments on commit 61f2445

Please sign in to comment.