forked from playcanvas/engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathskybox.js
More file actions
39 lines (33 loc) · 1.69 KB
/
skybox.js
File metadata and controls
39 lines (33 loc) · 1.69 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
import { SEMANTIC_POSITION } from '../../constants.js';
import { shaderChunks } from '../chunks/chunks.js';
import { gammaCode, precisionCode, tonemapCode } from './common.js';
const skybox = {
generateKey: function (options) {
const key = "skybox" + options.rgbm + " " + options.hdr + " " + options.fixSeams + "" +
options.toneMapping + "" + options.gamma + "" + options.useIntensity + "" +
options.useCubeMapRotation + "" + options.useRightHandedCubeMap + "" + options.mip;
return key;
},
createShaderDefinition: function (device, options) {
const mip2size = [128, 64, 32, 16, 8, 4, 2];
let fshader = precisionCode(device);
fshader += options.useCubeMapRotation ? '#define CUBEMAP_ROTATION\n' : '';
fshader += options.useRightHandedCubeMap ? '#define RIGHT_HANDED_CUBEMAP\n' : '';
fshader += options.mip ? shaderChunks.fixCubemapSeamsStretchPS : shaderChunks.fixCubemapSeamsNonePS;
fshader += options.useIntensity ? shaderChunks.envMultiplyPS : shaderChunks.envConstPS;
fshader += gammaCode(options.gamma);
fshader += tonemapCode(options.toneMapping);
fshader += shaderChunks.rgbmPS;
fshader += shaderChunks.skyboxHDRPS
.replace(/\$textureCubeSAMPLE/g, options.rgbm ? "textureCubeRGBM" : (options.hdr ? "textureCube" : "textureCubeSRGB"))
.replace(/\$FIXCONST/g, (1 - 1 / mip2size[options.mip]) + "");
return {
attributes: {
aPosition: SEMANTIC_POSITION
},
vshader: shaderChunks.skyboxVS,
fshader: fshader
};
}
};
export { skybox };