-
Notifications
You must be signed in to change notification settings - Fork 136
feat: HBAO + SSGI + TRAA + MotionBlur #211
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
Open
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
f12d4b7
feat: SSGI
CodyJasonBennett a72c58d
chore: add SSGI story
CodyJasonBennett 7dfefd8
chore: cleanup
CodyJasonBennett 0d5e78c
refactor: split up passes
CodyJasonBennett 0df7e3e
chore: cleanup
CodyJasonBennett 9060da6
Merge branch 'master' into feat/ssgi
CodyJasonBennett 0ad6cc1
chore: use better defaults in storybook
CodyJasonBennett 5d048d7
feat: MotionBlur
CodyJasonBennett 9d6f08f
chore: cleanup
CodyJasonBennett a37269e
chore(SSGI): cleanup
CodyJasonBennett c861e3c
feat: HBAO
CodyJasonBennett 0927cce
Merge branch 'master' into feat/ssgi
CodyJasonBennett 65648d1
Merge branch 'master' into feat/ssgi
CodyJasonBennett 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
Binary file added
.storybook/public/porsche.glb
Binary file not shown.
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
56 changes: 56 additions & 0 deletions
.storybook/stories/HBAO.stories.tsx
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,56 @@ | ||
| import * as React from 'react' | ||
| import * as THREE from 'three' | ||
| import type { Meta, StoryObj } from '@storybook/react' | ||
| import { EffectComposer, HBAO as HBAOImpl } from '../../src' | ||
| import { Canvas } from '@react-three/fiber' | ||
| import { Environment, useGLTF, OrbitControls } from '@react-three/drei' | ||
|
|
||
| const meta = { | ||
| title: 'Effects/HBAO', | ||
| component: HBAOImpl, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| }, | ||
| } satisfies Meta<typeof HBAOImpl> | ||
| export default meta | ||
|
|
||
| function Model() { | ||
| const gltf = useGLTF('/porsche.glb') | ||
| return <primitive object={gltf.scene} /> | ||
| } | ||
|
|
||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| export const HBAO: Story = { | ||
| render: (args) => ( | ||
| <Canvas gl={{ antialias: false }} camera={{ fov: 35, position: [5, 3, 5] }}> | ||
| <OrbitControls /> | ||
| <Environment preset="city" /> | ||
| <EffectComposer disableNormalPass multisampling={0}> | ||
| <HBAOImpl {...args} /> | ||
| </EffectComposer> | ||
| <Model /> | ||
| <directionalLight position={[217, 43, 76]} /> | ||
| </Canvas> | ||
| ), | ||
| args: { | ||
| // AO | ||
| resolutionScale: 1, | ||
| spp: 8, | ||
| distance: 2, | ||
| distancePower: 1, | ||
| power: 2, | ||
| bias: 40, | ||
| thickness: 0.075, | ||
| color: new THREE.Color('black'), | ||
| useNormalPass: false, | ||
| // Poisson | ||
| iterations: 1, | ||
| radius: 8, | ||
| rings: 5.625, | ||
| lumaPhi: 10, | ||
| depthPhi: 2, | ||
| normalPhi: 3.25, | ||
| samples: 16, | ||
| }, | ||
| } |
59 changes: 59 additions & 0 deletions
.storybook/stories/SSGI.stories.tsx
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,59 @@ | ||
| import * as React from 'react' | ||
| import type { Meta, StoryObj } from '@storybook/react' | ||
| import { EffectComposer, SSGI as SSGIImpl, TRAA, MotionBlur } from '../../src' | ||
| import { Canvas } from '@react-three/fiber' | ||
| import { Environment, useGLTF, OrbitControls } from '@react-three/drei' | ||
|
|
||
| const meta = { | ||
| title: 'Effects/SSGI', | ||
| component: SSGIImpl, | ||
| parameters: { | ||
| layout: 'fullscreen', | ||
| }, | ||
| } satisfies Meta<typeof SSGIImpl> | ||
| export default meta | ||
|
|
||
| function Model() { | ||
| const gltf = useGLTF('/porsche.glb') | ||
| return <primitive object={gltf.scene} /> | ||
| } | ||
|
|
||
| type Story = StoryObj<typeof meta> | ||
|
|
||
| export const SSGI: Story = { | ||
| render: (args) => ( | ||
| <Canvas gl={{ antialias: false }} camera={{ fov: 35, position: [5, 3, 5] }}> | ||
| <OrbitControls /> | ||
| <Environment preset="city" /> | ||
| <EffectComposer disableNormalPass multisampling={0}> | ||
| <SSGIImpl {...args} /> | ||
| <TRAA /> | ||
| <MotionBlur /> | ||
| </EffectComposer> | ||
| <Model /> | ||
| <directionalLight position={[217, 43, 76]} /> | ||
| </Canvas> | ||
| ), | ||
| args: { | ||
| distance: 10, | ||
| thickness: 10, | ||
| autoThickness: false, | ||
| maxRoughness: 1, | ||
| blend: 0.9, | ||
| denoiseIterations: 1, | ||
| denoiseKernel: 2, | ||
| denoiseDiffuse: 10, | ||
| denoiseSpecular: 10, | ||
| depthPhi: 2, | ||
| normalPhi: 50, | ||
| roughnessPhi: 1, | ||
| envBlur: 0.5, | ||
| importanceSampling: true, | ||
| directLightMultiplier: 1, | ||
| steps: 20, | ||
| refineSteps: 5, | ||
| spp: 1, | ||
| resolutionScale: 1, | ||
| missedRays: false, | ||
| }, | ||
| } |
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
121 changes: 121 additions & 0 deletions
src/passes/HBAO.tsx
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,121 @@ | ||
| import { forwardRef, useContext, useEffect, useMemo } from 'react' | ||
| import * as THREE from 'three' | ||
| import { EffectComposer, EffectPass } from 'postprocessing' | ||
| // @ts-ignore | ||
| import { VelocityDepthNormalPass, HBAOEffect } from 'realism-effects' | ||
| import { EffectComposerContext } from '../EffectComposer' | ||
| import { useVelocityBuffer } from './useVelocityBuffer' | ||
|
|
||
| export interface HBAOOptions { | ||
| // AO options | ||
| resolutionScale: number | ||
| spp: number | ||
| distance: number | ||
| distancePower: number | ||
| power: number | ||
| bias: number | ||
| thickness: number | ||
| color: THREE.Color | ||
| useNormalPass: boolean | ||
| velocityDepthNormalPass: VelocityDepthNormalPass | null | ||
| normalTexture: THREE.Texture | null | ||
| // Poisson blur options | ||
| iterations: number | ||
| radius: number | ||
| rings: number | ||
| lumaPhi: number | ||
| depthPhi: number | ||
| normalPhi: number | ||
| samples: number | ||
| // normalTexture: THREE.Texture | null | ||
| } | ||
|
|
||
| export class HBAOPass extends EffectPass { | ||
| constructor(composer: EffectComposer, camera: THREE.Camera, scene: THREE.Scene, options?: Partial<HBAOOptions>) { | ||
| super(camera, new HBAOEffect(composer, camera, scene, options)) | ||
| } | ||
| } | ||
|
|
||
| export interface HBAOProps extends Omit<Partial<HBAOOptions>, 'velocityDepthNormalPass'>, Partial<HBAOPass> {} | ||
|
|
||
| export const HBAO = forwardRef<HBAOPass, HBAOProps>(function HBAO( | ||
| { | ||
| // AO | ||
| resolutionScale = 1, | ||
| spp = 8, | ||
| distance = 2, | ||
| distancePower = 1, | ||
| power = 2, | ||
| bias = 40, | ||
| thickness = 0.075, | ||
| color = new THREE.Color('black'), | ||
| useNormalPass = false, | ||
| normalTexture = null, | ||
| // Poisson | ||
| iterations = 1, | ||
| radius = 8, | ||
| rings = 5.625, | ||
| lumaPhi = 10, | ||
| depthPhi = 2, | ||
| normalPhi = 3.25, | ||
| samples = 16, | ||
| ...props | ||
| }, | ||
| ref | ||
| ) { | ||
| const velocityDepthNormalPass = useVelocityBuffer() | ||
| const { composer, camera, scene } = useContext(EffectComposerContext) | ||
| const effect = useMemo( | ||
| () => | ||
| new HBAOPass(composer, camera, scene, { | ||
| resolutionScale, | ||
| spp, | ||
| distance, | ||
| distancePower, | ||
| power, | ||
| bias, | ||
| thickness, | ||
| color, | ||
| useNormalPass, | ||
| velocityDepthNormalPass, | ||
| normalTexture, | ||
| iterations, | ||
| radius, | ||
| rings, | ||
| lumaPhi, | ||
| depthPhi, | ||
| normalPhi, | ||
| samples, | ||
| }), | ||
| [ | ||
| composer, | ||
| camera, | ||
| scene, | ||
| resolutionScale, | ||
| spp, | ||
| distance, | ||
| distancePower, | ||
| power, | ||
| bias, | ||
| thickness, | ||
| color, | ||
| useNormalPass, | ||
| velocityDepthNormalPass, | ||
| normalTexture, | ||
| iterations, | ||
| radius, | ||
| rings, | ||
| lumaPhi, | ||
| depthPhi, | ||
| normalPhi, | ||
| samples, | ||
| ] | ||
| ) | ||
| useEffect(() => { | ||
| return () => { | ||
| effect.dispose() | ||
| } | ||
| }, [effect]) | ||
|
|
||
| return <primitive {...props} ref={ref} object={effect} /> | ||
| }) |
27 changes: 27 additions & 0 deletions
src/passes/MotionBlur.tsx
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,27 @@ | ||
| import { forwardRef, useContext, useEffect, useMemo } from 'react' | ||
| import { VelocityBuffer, useVelocityBuffer } from './useVelocityBuffer' | ||
| import { EffectPass } from 'postprocessing' | ||
| // @ts-ignore | ||
| import { MotionBlurEffect } from 'realism-effects' | ||
| import { EffectComposerContext } from '../EffectComposer' | ||
|
|
||
| export class MotionBlurPass extends EffectPass { | ||
| constructor(camera: THREE.Camera, velocityBuffer: VelocityBuffer) { | ||
| super(camera, new MotionBlurEffect(velocityBuffer)) | ||
| } | ||
| } | ||
|
|
||
| export interface MotionBlurProps extends Partial<MotionBlurPass> {} | ||
|
|
||
| export const MotionBlur = forwardRef<MotionBlurPass, MotionBlurProps>(function MotionBlur(props, ref) { | ||
| const velocityBuffer = useVelocityBuffer() | ||
| const { camera } = useContext(EffectComposerContext) | ||
| const effect = useMemo(() => new MotionBlurPass(camera, velocityBuffer), [camera, velocityBuffer]) | ||
| useEffect(() => { | ||
| return () => { | ||
| effect.dispose() | ||
| } | ||
| }, [effect]) | ||
|
|
||
| return <primitive {...props} ref={ref} object={effect} /> | ||
| }) |
File renamed without changes.
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.