-
-
Notifications
You must be signed in to change notification settings - Fork 35.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MeshVelocityMaterial: render a scene's velocity field to a buffer (us…
…eful for motion blur, TRAA post effects) (#23784) * beginning work on TRAA pass. * more work on TRAA. * remove TRAA for now. * velocity material is working. * update default channel in example. * Update MeshVelocityMaterial.js * Update ShaderLib.js * add mention of velocity in channel example description * clean up MeshVelocityMaterial class. * Update MeshVelocityMaterial.js * move velocity shader out of core and into examples. * channel example working again. * make Object3D.matrixWorldPrevious optional. * cleanup of PR. * Update webgl_materials_channels.html Co-authored-by: Michael Herzog <michael.herzog@human-interactive.org>
Showing
3 changed files
with
175 additions
and
3 deletions.
There are no files selected for viewing
This file contains 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,128 @@ | ||
import { | ||
UniformsLib, | ||
UniformsUtils, | ||
Matrix4 | ||
} from 'three'; | ||
|
||
/** | ||
* Mesh Velocity Shader @bhouston | ||
*/ | ||
|
||
const VelocityShader = { | ||
|
||
uniforms: UniformsUtils.merge( [ | ||
UniformsLib.common, | ||
UniformsLib.displacementmap, | ||
{ | ||
modelMatrixPrev: { value: new Matrix4() }, | ||
currentProjectionViewMatrix: { value: new Matrix4() }, | ||
previousProjectionViewMatrix: { value: new Matrix4() } | ||
} | ||
] ), | ||
|
||
vertexShader: /* glsl */` | ||
#define NORMAL | ||
#if defined( FLAT_SHADED ) || defined( USE_BUMPMAP ) || defined( TANGENTSPACE_NORMALMAP ) | ||
varying vec3 vViewPosition; | ||
#endif | ||
#include <common> | ||
#include <packing> | ||
#include <uv_pars_vertex> | ||
#include <displacementmap_pars_vertex> | ||
#include <normal_pars_vertex> | ||
#include <morphtarget_pars_vertex> | ||
#include <skinning_pars_vertex> | ||
#include <logdepthbuf_pars_vertex> | ||
#include <clipping_planes_pars_vertex> | ||
uniform mat4 previousProjectionViewMatrix; | ||
uniform mat4 currentProjectionViewMatrix; | ||
uniform mat4 modelMatrixPrev; | ||
varying vec4 clipPositionCurrent; | ||
varying vec4 clipPositionPrevious; | ||
void main() { | ||
#include <uv_vertex> | ||
#include <beginnormal_vertex> | ||
#include <morphnormal_vertex> | ||
#include <skinbase_vertex> | ||
#include <skinnormal_vertex> | ||
#include <defaultnormal_vertex> | ||
#include <normal_vertex> | ||
#include <begin_vertex> | ||
#include <morphtarget_vertex> | ||
#include <displacementmap_vertex> | ||
#include <morphtarget_vertex> | ||
#include <skinning_vertex> | ||
#ifdef USE_SKINNING | ||
vec4 mvPosition = modelViewMatrix * skinned; | ||
clipPositionCurrent = currentProjectionViewMatrix * modelMatrix * skinned; | ||
clipPositionPrevious = previousProjectionViewMatrix * modelMatrixPrev * skinned; | ||
#else | ||
vec4 mvPosition = modelViewMatrix * vec4( transformed, 1.0 ); | ||
clipPositionCurrent = currentProjectionViewMatrix * modelMatrix * vec4( transformed, 1.0 ); | ||
clipPositionPrevious = previousProjectionViewMatrix * modelMatrixPrev * vec4( transformed, 1.0 ); | ||
#endif | ||
gl_Position = projectionMatrix * mvPosition; | ||
#include <logdepthbuf_vertex> | ||
#include <clipping_planes_vertex> | ||
} | ||
`, | ||
fragmentShader: /* glsl */` | ||
#define NORMAL | ||
uniform float opacity; | ||
#include <packing> | ||
#include <uv_pars_fragment> | ||
#include <map_pars_fragment> | ||
#include <alphamap_pars_fragment> | ||
#include <alphatest_pars_fragment> | ||
#include <logdepthbuf_pars_fragment> | ||
#include <clipping_planes_pars_fragment> | ||
varying vec4 clipPositionCurrent; | ||
varying vec4 clipPositionPrevious; | ||
void main() { | ||
vec4 diffuseColor = vec4( 1.0 ); | ||
diffuseColor.a = opacity; | ||
#include <map_fragment> | ||
#include <alphamap_fragment> | ||
#include <alphatest_fragment> | ||
vec2 ndcPositionCurrent = clipPositionCurrent.xy/clipPositionCurrent.w; | ||
vec2 ndcPositionPrevious = clipPositionPrevious.xy/clipPositionPrevious.w; | ||
vec2 vel = ( ndcPositionCurrent - ndcPositionPrevious ) * 0.5; | ||
vel = vel * 0.5 + 0.5; | ||
vec2 v1 = packDepthToRG(vel.x); | ||
vec2 v2 = packDepthToRG(vel.y); | ||
gl_FragColor = vec4(v1.x, v1.y, v2.x, v2.y); | ||
#include <logdepthbuf_fragment> | ||
} | ||
` | ||
}; | ||
|
||
export { VelocityShader }; |
This file contains 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 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