-
Notifications
You must be signed in to change notification settings - Fork 57
/
Copy pathpbr2.html
138 lines (125 loc) · 4.32 KB
/
pbr2.html
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<title>Hilo3d PBR Demo</title>
<link rel="stylesheet" type="text/css" href="./example.css">
</head>
<body>
<div id="container"></div>
<script src="../build/Hilo3d.js"></script>
<script src="./js/stats.js"></script>
<script src="./js/OrbitControls.js"></script>
<script src="./js/init.js"></script>
<script src="./js/postProcess.js"></script>
<script>
initModel();
initLight();
function initModel(){
var gltfURL = './models/BoomBox/BoomBox.gltf';
var loadQueue = new Hilo3d.LoadQueue([{
type: 'CubeTexture',
images: [
'./image/bakedDiffuse_01.jpg',
'./image/bakedDiffuse_02.jpg',
'./image/bakedDiffuse_03.jpg',
'./image/bakedDiffuse_04.jpg',
'./image/bakedDiffuse_05.jpg',
'./image/bakedDiffuse_06.jpg'
]
}, {
type: 'CubeTexture',
right: './image/px.jpg',
left: './image/nx.jpg',
top: './image/py.jpg',
bottom: './image/ny.jpg',
front: './image/pz.jpg',
back: './image/nz.jpg',
magFilter: Hilo3d.constants.LINEAR,
minFilter: Hilo3d.constants.LINEAR_MIPMAP_LINEAR
},{
src: './image/brdfLUT.png',
wrapS: Hilo3d.constants.CLAMP_TO_EDGE,
wrapT: Hilo3d.constants.CLAMP_TO_EDGE,
type:'Texture'
}]).start().on('complete', function(){
var result = loadQueue.getAllContent();
var diffuseEnvMap = result[0];
var specularEnvMap = result[1];
var brdfTexture = result[2];
var node = new Hilo3d.Node();
node.setScale(0.2);
stage.addChild(node);
var geometry = new Hilo3d.SphereGeometry({
radius: 0.45,
heightSegments: 16,
widthSegments: 32
});
var colors = [
[0.56, 0.57, 0.58], //铁
[0.95, 0.64, 0.54], //铜
[1, 0.71, 0.29], //金
[0.95, 0.93, 0.88], //银
];
var num = 8;
for(var i = 0;i < num; i ++){
for(var j = 0;j < num;j ++){
var x = i - num*.5;
var y = j - num*.5;
var metallic = i/num;
var roughness = j/num;
var len = colors.length;
colors.forEach(function(color, index){
material = new Hilo3d.PBRMaterial({
baseColor: new Hilo3d.Color(color[0], color[1], color[2]),
metallic: metallic,
roughness: roughness,
brdfLUT: brdfTexture,
diffuseEnvMap: diffuseEnvMap,
specularEnvMap: specularEnvMap
});
var mesh = new Hilo3d.Mesh({
geometry: geometry,
material: material,
x:x,
y:y,
z:(index - len * .5) * 2
});
node.addChild(mesh);
});
}
}
var skyBox = new Hilo3d.Mesh({
geometry: new Hilo3d.BoxGeometry(),
material: new Hilo3d.BasicMaterial({
lightType: 'NONE',
side: Hilo3d.constants.BACK,
diffuse: specularEnvMap
})
}).addTo(stage);
skyBox.setScale(20);
});
}
function initLight(){
ambientLight.amount = 0.03;
var pointLight = new Hilo3d.PointLight({
color:new Hilo3d.Color(.3, .3, .3),
x:5,
y:0,
z:5,
range:500
});
stage.addChild(pointLight);
Hilo3d.Tween.to(pointLight, {
x:-5
}, {
duration:2000,
loop:true,
reverse:true
});
}
</script>
</body>
</html>