forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsimple-post-effect.js
More file actions
93 lines (82 loc) · 2.78 KB
/
simple-post-effect.js
File metadata and controls
93 lines (82 loc) · 2.78 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
pc.extend(pc, (function () {
'use strict';
// Draws shaded full-screen quad in a single call
var _postEffectQuadVB = null;
var _postEffectQuadDraw = {
type: pc.PRIMITIVE_TRISTRIP,
base: 0,
count: 4,
indexed: false
};
function drawQuadWithShader(device, target, shader, rect, scissorRect, useBlend) {
if (_postEffectQuadVB === null) {
var vertexFormat = new pc.VertexFormat(device, [{
semantic: pc.SEMANTIC_POSITION,
components: 2,
type: pc.TYPE_FLOAT32
}]);
_postEffectQuadVB = new pc.VertexBuffer(device, vertexFormat, 4);
var iterator = new pc.VertexIterator(_postEffectQuadVB);
iterator.element[pc.SEMANTIC_POSITION].set(-1.0, -1.0);
iterator.next();
iterator.element[pc.SEMANTIC_POSITION].set(1.0, -1.0);
iterator.next();
iterator.element[pc.SEMANTIC_POSITION].set(-1.0, 1.0);
iterator.next();
iterator.element[pc.SEMANTIC_POSITION].set(1.0, 1.0);
iterator.end();
}
var oldRt = device.renderTarget;
device.setRenderTarget(target);
device.updateBegin();
var x, y, w, h;
var sx, sy, sw, sh;
if (!rect) {
w = (target !== null) ? target.width : device.width;
h = (target !== null) ? target.height : device.height;
x = 0;
y = 0;
} else {
x = rect.x;
y = rect.y;
w = rect.z;
h = rect.w;
}
if (!scissorRect) {
sx = x;
sy = y;
sw = w;
sh = h;
} else {
sx = scissorRect.x;
sy = scissorRect.y;
sw = scissorRect.z;
sh = scissorRect.w;
}
device.setViewport(x, y, w, h);
device.setScissor(sx, sy, sw, sh);
var oldDepthTest = device.getDepthTest();
var oldDepthWrite = device.getDepthWrite();
var oldCull = device.getCullMode();
device.setDepthTest(false);
device.setDepthWrite(false);
device.setCullMode(pc.CULLFACE_NONE);
if (!useBlend) device.setBlending(false);
device.setVertexBuffer(_postEffectQuadVB, 0);
device.setShader(shader);
device.draw(_postEffectQuadDraw);
device.setDepthTest(oldDepthTest);
device.setDepthWrite(oldDepthWrite);
device.setCullMode(oldCull);
device.updateEnd();
device.setRenderTarget(oldRt);
device.updateBegin();
}
function destroyPostEffectQuad() {
_postEffectQuadVB = null;
}
return {
drawQuadWithShader: drawQuadWithShader,
destroyPostEffectQuad: destroyPostEffectQuad,
};
}()));