-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
64 lines (53 loc) · 2.52 KB
/
index.js
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
var ConvolutedCubeMap = require('./ConvolutedCubeMap');
var upgradeFragmentShaderToHaveFakeHDRIOutput = require('./upgradeFragmentShaderToHaveFakeHDRIOutput');
//awesome shim to empower native materials with fake 8bit hdri hack for mobile
var materialsToUpgrage = [
'basic',
'phong'
];
materialsToUpgrage.forEach(function(mat) {
var shader = THREE.ShaderLib[mat];
shader.fragmentShader = upgradeFragmentShaderToHaveFakeHDRIOutput(shader.fragmentShader);
});
console.warn('warning: THREEjs has been shimmed with extra shader routines to provide HDRI emulation via the alpha channel. This may break certain expected behaviours.');
//end shim
function LightProbe(near, far, resolution, type) {
near = near || .01;
far = far || 1000;
resolution = resolution || 128;
this.bufferType = type;
var format;
if(type === ConvolutedCubeMap.FakeHDRI || type === ConvolutedCubeMap.FakeHDRIThrough) {
type = THREE.UnsignedByteType;
format = THREE.RGBAFormat;
}
THREE.CubeCamera.call(this, near, far, resolution, type, format);
if(this.renderTarget.type !== this.bufferType) console.log("LightProbe: WARNING: This version of three.js does not support Float Type CubeCamera. This is OK, but if you use a patched version of threejs, cubemaps can be HDRI!");
this.convolutedCubeMaps = [];
}
LightProbe.prototype = Object.create(THREE.CubeCamera.prototype);
LightProbe.prototype.update = function(renderer, scene, updateAllconvolutionCubeMaps) {
this.updateCubeMap(renderer, scene);
if(updateAllconvolutionCubeMaps !== false) {
for (var i = this.convolutedCubeMaps.length - 1; i >= 0; i--) {
this.convolutedCubeMaps[i].update(renderer);
};
}
}
LightProbe.prototype.updateManual = function(renderer, renderTarget, updateAllconvolutionCubeMaps) {
this.renderTarget = renderTarget;
if(updateAllconvolutionCubeMaps !== false) {
for (var i = this.convolutedCubeMaps.length - 1; i >= 0; i--) {
this.convolutedCubeMaps[i].sourceCubMap = renderTarget;
this.convolutedCubeMaps[i].update(renderer);
};
}
}
LightProbe.prototype.getCubeMapGenerator = function(resolution, blurStrength, brightness, iterations, flipX, prerenderCallback, postrenderCallback) {
var convolutedCubeMap = new ConvolutedCubeMap(this.renderTarget, resolution, blurStrength, brightness, iterations, flipX, this.bufferType, prerenderCallback, postrenderCallback);
this.convolutedCubeMaps.push(convolutedCubeMap);
return convolutedCubeMap;
}
LightProbe.FakeHDRI = ConvolutedCubeMap.FakeHDRI;
LightProbe.FakeHDRIThrough = ConvolutedCubeMap.FakeHDRIThrough;
module.exports = LightProbe;