-
Notifications
You must be signed in to change notification settings - Fork 120
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
CodyJasonBennett
wants to merge
13
commits into
pmndrs:master
Choose a base branch
from
CodyJasonBennett:feat/ssgi
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 2 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 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
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,57 @@ | ||
import * as React from 'react' | ||
import type { Meta, StoryObj } from '@storybook/react' | ||
import { EffectComposer, SSGI as SSGIImpl } 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> | ||
<SSGIImpl {...args} /> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
import * as THREE from 'three' | ||
import { useMemo, useEffect, forwardRef } from 'react' | ||
import { useThree } from '@react-three/fiber' | ||
import { Pass, EffectPass } from 'postprocessing' | ||
// @ts-ignore | ||
import { VelocityDepthNormalPass, SSGIEffect, TRAAEffect } from 'realism-effects' | ||
|
||
export interface SSGIOptions { | ||
distance: number | ||
thickness: number | ||
autoThickness: boolean | ||
maxRoughness: number | ||
blend: number | ||
denoiseIterations: number | ||
denoiseKernel: number | ||
denoiseDiffuse: number | ||
denoiseSpecular: number | ||
depthPhi: number | ||
normalPhi: number | ||
roughnessPhi: number | ||
envBlur: number | ||
importanceSampling: boolean | ||
directLightMultiplier: number | ||
steps: number | ||
refineSteps: number | ||
spp: number | ||
resolutionScale: number | ||
missedRays: boolean | ||
} | ||
|
||
class SSGIPass extends Pass { | ||
readonly velocityDepthNormalPass: VelocityDepthNormalPass | ||
readonly ssgiPass: EffectPass | ||
readonly traaPass: EffectPass | ||
|
||
constructor(scene: THREE.Scene, camera: THREE.Camera, options: SSGIOptions = {} as SSGIOptions) { | ||
super('SSGIPass', scene, camera) | ||
|
||
this.velocityDepthNormalPass = new VelocityDepthNormalPass(scene, camera) | ||
this.ssgiPass = new EffectPass(camera, new SSGIEffect(scene, camera, this.velocityDepthNormalPass, options)) | ||
this.traaPass = new EffectPass(camera, new TRAAEffect(scene, camera, this.velocityDepthNormalPass)) | ||
} | ||
|
||
initialize(renderer: THREE.WebGLRenderer, alpha: boolean, frameBufferType: number) { | ||
this.velocityDepthNormalPass.initialize(renderer, alpha, frameBufferType) | ||
this.ssgiPass.initialize(renderer, alpha, frameBufferType) | ||
this.traaPass.initialize(renderer, alpha, frameBufferType) | ||
} | ||
|
||
setSize(width: number, height: number): void { | ||
this.velocityDepthNormalPass.setSize(width, height) | ||
this.ssgiPass.setSize(width, height) | ||
this.traaPass.setSize(width, height) | ||
} | ||
|
||
render( | ||
renderer: THREE.WebGLRenderer, | ||
inputBuffer: THREE.WebGLRenderTarget | null, | ||
outputBuffer: THREE.WebGLRenderTarget | null, | ||
deltaTime?: number, | ||
stencilTest?: boolean | ||
): void { | ||
this.velocityDepthNormalPass.render(renderer, outputBuffer, inputBuffer, deltaTime, stencilTest) | ||
this.ssgiPass.render(renderer, outputBuffer, inputBuffer, deltaTime, stencilTest) | ||
this.traaPass.renderToScreen = this.renderToScreen | ||
this.traaPass.render(renderer, inputBuffer, outputBuffer, deltaTime, stencilTest) | ||
CodyJasonBennett marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
export interface SSGIProps extends SSGIOptions {} | ||
|
||
export const SSGI = forwardRef<SSGIPass, SSGIOptions>(function SSGI( | ||
{ | ||
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, | ||
...props | ||
}, | ||
ref | ||
) { | ||
const { scene, camera } = useThree() | ||
const effect = useMemo( | ||
() => | ||
new SSGIPass(scene, camera, { | ||
distance, | ||
thickness, | ||
autoThickness, | ||
maxRoughness, | ||
blend, | ||
denoiseIterations, | ||
denoiseKernel, | ||
denoiseDiffuse, | ||
denoiseSpecular, | ||
depthPhi, | ||
normalPhi, | ||
roughnessPhi, | ||
envBlur, | ||
importanceSampling, | ||
directLightMultiplier, | ||
steps, | ||
refineSteps, | ||
spp, | ||
resolutionScale, | ||
missedRays, | ||
}), | ||
[ | ||
scene, | ||
camera, | ||
distance, | ||
thickness, | ||
autoThickness, | ||
maxRoughness, | ||
blend, | ||
denoiseIterations, | ||
denoiseKernel, | ||
denoiseDiffuse, | ||
denoiseSpecular, | ||
depthPhi, | ||
normalPhi, | ||
roughnessPhi, | ||
envBlur, | ||
importanceSampling, | ||
directLightMultiplier, | ||
steps, | ||
refineSteps, | ||
spp, | ||
resolutionScale, | ||
missedRays, | ||
] | ||
) | ||
|
||
useEffect(() => { | ||
return () => effect.dispose() | ||
}, [effect]) | ||
|
||
return <primitive {...props} ref={ref} object={effect} /> | ||
}) |
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
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.
Uh oh!
There was an error while loading. Please reload this page.