forked from markaren/threepp
-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathhdr_envmap.cpp
More file actions
45 lines (33 loc) · 1.26 KB
/
Copy pathhdr_envmap.cpp
File metadata and controls
45 lines (33 loc) · 1.26 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
#include "threepp/loaders/RGBELoader.hpp"
#include "threepp/threepp.hpp"
using namespace threepp;
int main() {
Canvas canvas("HDR Environment Map");
auto renderer = createRenderer(canvas);
renderer->toneMapping = ToneMapping::ACESFilmic;
renderer->toneMappingExposure = 1.0f;
auto scene = Scene::create();
PerspectiveCamera camera(45, canvas.aspect(), 0.1f, 1000);
camera.position.set(0, 0, 5);
RGBELoader hdrLoader;
if (auto hdrTexture = hdrLoader.load(std::string(DATA_FOLDER) + "/textures/env/san_giuseppe_bridge/san_giuseppe_bridge_4k.hdr")) {
scene->background = hdrTexture;
scene->environment = hdrTexture;
}
// Metallic sphere — IBL from the HDR environment
auto sphereGeo = SphereGeometry::create(1.0f, 64, 32);
auto sphereMat = MeshStandardMaterial::create();
sphereMat->metalness = 1.0f;
sphereMat->roughness = 0.2f;
auto sphere = Mesh::create(sphereGeo, sphereMat);
scene->add(sphere);
OrbitControls controls{camera, canvas};
canvas.onWindowResize([&](WindowSize size) {
camera.aspect = size.aspect();
camera.updateProjectionMatrix();
renderer->setSize(size);
});
canvas.animate([&] {
renderer->render(*scene, camera);
});
}