Skip to content

Commit 4c09a8f

Browse files
author
Martin Valigursky
committed
Added DOF support to CameraFrame script
1 parent 602e544 commit 4c09a8f

File tree

1 file changed

+66
-2
lines changed

1 file changed

+66
-2
lines changed

scripts/utils/camera-frame.mjs

+66-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// Camera Frame v 1.0
2+
13
/* eslint-disable-next-line import/no-unresolved */
24
import { CameraFrame as EngineCameraFrame, Script, Color } from 'playcanvas';
35

@@ -32,7 +34,9 @@ const DebugType = {
3234
SCENE: 'scene',
3335
SSAO: 'ssao',
3436
BLOOM: 'bloom',
35-
VIGNETTE: 'vignette'
37+
VIGNETTE: 'vignette',
38+
DOFCOC: 'dofcoc',
39+
DOFBLUR: 'dofblur'
3640
};
3741

3842
/** @interface */
@@ -258,6 +262,47 @@ class Taa {
258262
jitter = 1;
259263
}
260264

265+
/** @interface */
266+
class Dof {
267+
enabled = false;
268+
269+
highQuality = true;
270+
271+
nearBlur = false;
272+
273+
/**
274+
* @precision 2
275+
* @step 1
276+
*/
277+
focusDistance = 100;
278+
279+
/**
280+
* @precision 2
281+
* @step 1
282+
*/
283+
focusRange = 10;
284+
285+
/**
286+
* @precision 2
287+
* @step 0.1
288+
*/
289+
blurRadius = 3;
290+
291+
/**
292+
* @range [1, 10]
293+
* @precision 0
294+
* @step 1
295+
*/
296+
blurRings = 4;
297+
298+
/**
299+
* @range [1, 10]
300+
* @precision 0
301+
* @step 1
302+
*/
303+
blurRingPoints = 5;
304+
}
305+
261306
class CameraFrame extends Script {
262307
/**
263308
* @attribute
@@ -301,6 +346,12 @@ class CameraFrame extends Script {
301346
*/
302347
fringing = new Fringing();
303348

349+
/**
350+
* @attribute
351+
* @type {Dof}
352+
*/
353+
dof = new Dof();
354+
304355
engineCameraFrame = new EngineCameraFrame(this.app, this.entity.camera);
305356

306357
initialize() {
@@ -321,7 +372,7 @@ class CameraFrame extends Script {
321372
postUpdate(dt) {
322373

323374
const cf = this.engineCameraFrame;
324-
const { rendering, bloom, grading, vignette, fringing, taa, ssao } = this;
375+
const { rendering, bloom, grading, vignette, fringing, taa, ssao, dof } = this;
325376

326377
const dstRendering = cf.rendering;
327378
dstRendering.renderFormats.length = 0;
@@ -385,6 +436,19 @@ class CameraFrame extends Script {
385436
const dstFringing = cf.fringing;
386437
dstFringing.intensity = fringing.enabled ? fringing.intensity : 0;
387438

439+
// dof
440+
const dstDof = cf.dof;
441+
dstDof.enabled = dof.enabled;
442+
if (dof.enabled) {
443+
dstDof.highQuality = dof.highQuality;
444+
dstDof.nearBlur = dof.nearBlur;
445+
dstDof.focusDistance = dof.focusDistance;
446+
dstDof.focusRange = dof.focusRange;
447+
dstDof.blurRadius = dof.blurRadius;
448+
dstDof.blurRings = dof.blurRings;
449+
dstDof.blurRingPoints = dof.blurRingPoints;
450+
}
451+
388452
// debugging
389453
cf.debug = rendering.debug;
390454

0 commit comments

Comments
 (0)