Skip to content

Commit

Permalink
feat: motion blur now renders with the correct orientation
Browse files Browse the repository at this point in the history
  • Loading branch information
zachHixson committed Feb 21, 2024
1 parent 0c747a3 commit 3cbab29
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 1 deletion.
2 changes: 2 additions & 0 deletions packages/core/shaders/moblur.glsl
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@
precision highp float;

uniform highp sampler3D srcTex;
uniform int canvasHeight;
uniform int samples;

out vec4 outColor;

void main(){
ivec2 texelCoord = ivec2(gl_FragCoord);
texelCoord.y = canvasHeight - 1 - texelCoord.y;
vec4 total = vec4(0.0);
for (int i = 0; i < samples; i++){
total += texelFetch(srcTex, ivec3(texelCoord, i), 0);
Expand Down
3 changes: 3 additions & 0 deletions packages/core/src/app/MoblurRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ export class MoblurRenderer {

private readonly computeContext: WebGL2RenderingContext;
private readonly sumTexture: Texture;
private readonly heightUniformLoc: WebGLUniformLocation;
private readonly sampleCountUniformLoc: WebGLUniformLocation;
private sampleCount: number = 1;
private duration: number = 1;
Expand Down Expand Up @@ -80,6 +81,7 @@ export class MoblurRenderer {
)!;
const program = WebGL.compileProgram(gl, vertexShader, moblurFS)!;
const divSrcUniformLoc = gl.getUniformLocation(program, 'srcTex')!;
this.heightUniformLoc = gl.getUniformLocation(program, 'canvasHeight')!;
this.sampleCountUniformLoc = gl.getUniformLocation(program, 'samples')!;
this.sumTexture = this.getSumTexture(gl, 2);
this.setupVertexBuffer(gl, program);
Expand Down Expand Up @@ -146,6 +148,7 @@ export class MoblurRenderer {
canvas.width = size.x;
canvas.height = size.y;

gl.uniform1i(this.heightUniformLoc, canvas.height);
gl.uniform1i(this.sampleCountUniformLoc, this.sampleCount);

//clear and resize gl contexts
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/app/ProjectMetadata.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ function createProjectMetadata(project: Project) {
motionBlurSamples: new NumberMetaField('motion blur samples', 1)
.setPresets([
{value: 1, text: '1'},
{value: 8, text: '8'},
{value: 8, text: '3'},
{value: 32, text: '8'},
{value: 32, text: '32'},
])
.setRange(1),
Expand Down

0 comments on commit 3cbab29

Please sign in to comment.