forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparticle.js
More file actions
109 lines (97 loc) · 4.93 KB
/
particle.js
File metadata and controls
109 lines (97 loc) · 4.93 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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
pc.programlib.particle = {
generateKey: function(device, options) {
var key = "particle";
for (var prop in options) {
if (options.hasOwnProperty(prop)) {
key += options[prop];
}
}
return key;
},
_animTex: function(options, chunk) {
var vshader = "";
vshader += options.animTexLoop? chunk.particleAnimFrameLoopVS : chunk.particleAnimFrameClampVS;
vshader += chunk.particleAnimTexVS;
return vshader;
},
createShaderDefinition: function(device, options) {
var chunk = pc.shaderChunks;
var vshader = "";
var fshader = pc.programlib.precisionCode(device) + "\n";
if (options.animTex) vshader += "\nuniform vec4 animTexParams;\n";
if (options.normal == 2) vshader += "\nvarying mat3 ParticleMat;\n";
if (options.normal == 1) vshader += "\nvarying vec3 Normal;\n";
if (options.soft) vshader += "\nvarying float vDepth;\n";
if (!options.useCpu) {
vshader += chunk.particle_initVS;
vshader += (options.pack8? chunk.particleInputRgba8PS : chunk.particleInputFloatPS);
vshader += chunk.particleVS;
if (options.localSpace) vshader += chunk.particle_localShiftVS;
if (options.animTex) vshader += this._animTex(options, chunk);
if (options.wrap) vshader += chunk.particle_wrapVS;
if (options.alignToMotion) vshader += chunk.particle_pointAlongVS;
vshader += options.mesh ? chunk.particle_meshVS : chunk.particle_billboardVS;
if (options.normal == 1) vshader += chunk.particle_normalVS;
if (options.normal == 2) vshader += chunk.particle_TBNVS;
if (options.stretch > 0.0) vshader += chunk.particle_stretchVS;
vshader += chunk.particle_endVS;
if (options.soft > 0) vshader += chunk.particle_softVS;
} else {
vshader += chunk.particle_cpuVS;
if (options.localSpace) vshader += chunk.particle_localShiftVS;
if (options.animTex) vshader += this._animTex(options, chunk);
//if (options.wrap) vshader += chunk.particle_wrapVS;
if (options.alignToMotion) vshader += chunk.particle_pointAlongVS;
vshader += options.mesh ? chunk.particle_meshVS : chunk.particle_billboardVS;
if (options.normal == 1) vshader += chunk.particle_normalVS;
if (options.normal == 2) vshader += chunk.particle_TBNVS;
if (options.stretch > 0.0) vshader += chunk.particle_stretchVS;
vshader += chunk.particle_cpu_endVS;
if (options.soft > 0) vshader += chunk.particle_softVS;
}
vshader += "}\n";
if (options.normal > 0) {
if (options.normal == 1) {
fshader += "\nvarying vec3 Normal;\n";
} else if (options.normal == 2) {
fshader += "\nvarying mat3 ParticleMat;\n";
}
fshader += "\nuniform vec3 lightCube[6];\n";
}
if (options.soft) fshader += "\nvarying float vDepth;\n";
if ((options.normal === 0) && (options.fog === "none")) options.srgb = false; // don't have to perform all gamma conversions when no lighting and fogging is used
fshader += pc.programlib.gammaCode(options.gamma);
fshader += pc.programlib.tonemapCode(options.toneMap);
if (options.fog === 'linear') {
fshader += chunk.fogLinearPS;
} else if (options.fog === 'exp') {
fshader += chunk.fogExpPS;
} else if (options.fog === 'exp2') {
fshader += chunk.fogExp2PS;
} else {
fshader += chunk.fogNonePS;
}
if (options.normal == 2) fshader += "\nuniform sampler2D normalMap;\n";
if (options.soft > 0) fshader += "\nuniform sampler2D uDepthMap;\n uniform vec4 uScreenSize;\n";
fshader += chunk.particlePS;
if (options.soft > 0) fshader += chunk.particle_softPS;
if (options.normal == 1) fshader += "\nvec3 normal = Normal;\n";
if (options.normal == 2) fshader += chunk.particle_normalMapPS;
if (options.normal > 0) fshader += options.halflambert ? chunk.particle_halflambertPS : chunk.particle_lambertPS;
if (options.normal > 0) fshader += chunk.particle_lightingPS;
if (options.blend==pc.BLEND_NORMAL) {
fshader += chunk.particle_blendNormalPS;
} else if (options.blend==pc.BLEND_ADDITIVE) {
fshader += chunk.particle_blendAddPS;
} else if (options.blend==pc.BLEND_MULTIPLICATIVE) {
fshader += chunk.particle_blendMultiplyPS;
}
fshader += chunk.particle_endPS;
var attributes = pc.shaderChunks.collectAttribs(vshader);
return {
attributes: attributes,
vshader: vshader,
fshader: fshader
};
}
};