纹理的颜色空间
代码
js
import * as THREE from 'three'
import { OrbitControls } from 'three/examples/jsm/controls/OrbitControls.js'
import { GUI } from 'three/examples/jsm/libs/lil-gui.module.min.js';
import { RGBELoader } from 'three/examples/jsm/loaders/RGBELoader.js';
const scene = new THREE.Scene();
const camera = new THREE.PerspectiveCamera(
45,
window.innerWidth / window.innerHeight,
0.1,
1000
)
const renderer = new THREE.WebGLRenderer()
renderer.setSize(window.innerWidth, window.innerHeight)
document.body.appendChild(renderer.domElement)
camera.position.z = 5;
camera.position.y = 2;
camera.position.x = 2;
camera.lookAt(0, 0, 0)
const axesHelper = new THREE.AxesHelper(5);
scene.add(axesHelper);
const controls = new OrbitControls(camera, renderer.domElement);
controls.enableDamping = true;
controls.dampingFactor = 0.05;
function animate() {
requestAnimationFrame(animate)
controls.update()
renderer.render(scene, camera)
}
animate()
window.addEventListener('resize', () => {
renderer.setSize(window.innerWidth, innerHeight)
camera.aspect = window.innerWidth / window.innerHeight
camera.updateProjectionMatrix()
})
let eventObj = {
Fullscreen: function () {
document.body.requestFullscreen()
},
ExitFullscreen: function () {
document.exitFullscreen()
}
}
const gui = new GUI()
gui.add(eventObj, 'Fullscreen').name('全屏')
gui.add(eventObj, 'ExitFullscreen').name('退出全屏')
let planeGeometry = new THREE.PlaneGeometry(1, 1)
let textureLoader = new THREE.TextureLoader()
let texture = textureLoader.load('./texture/watercover/CityNewYork002_COL_VAR1_1K.png')
// RGB空间
texture.colorSpace = THREE.SRGBColorSpace
// 线性空间 默认为线性空间
// texture.colorSpace = THREE.LinearSRGBColorSpace
let aoMap = textureLoader.load('./texture/watercover/CityNewYork002_AO_1K.jpg')
let alphaMap = textureLoader.load('./texture/door/height.jpg')
let lightMap = textureLoader.load('./texture/colors.png')
let specularMap = textureLoader.load('./texture/watercover/CityNewYork002_GLOSS_1K.jpg')
let rgbLoader = new RGBELoader()
rgbLoader.load('./texture/Alex_Hart-Nature_Lab_Bones_2k.hdr', (envMap) => {
envMap.mapping = THREE.EquirectangularReflectionMapping
scene.background = envMap
scene.environment = envMap
planeMaterial.envMap = envMap
})
let planeMaterial = new THREE.MeshBasicMaterial({
color: 0xffffff,
side: THREE.DoubleSide,
transparent: true,
aoMap: aoMap,
aoMapIntensity: 1,
reflectivity: 0.3,
specularMap: specularMap,
})
planeMaterial.map = texture
let plane = new THREE.Mesh(planeGeometry, planeMaterial)
scene.add(plane)
gui.add(planeMaterial, 'aoMapIntensity').min(0).max(1).name('ao强度')
// 设置纹理的颜色空间
gui.add(texture, 'colorSpace', {
SRGB: THREE.SRGBColorSpace,
Linear: THREE.LinearSRGBColorSpace
}).onChange(() => {
texture.needsUpdate = true
})
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
110
111
112
113
114
115
116
117
118
119
120
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
110
111
112
113
114
115
116
117
118
119
120