-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathPBRDemo.cpp
108 lines (93 loc) · 4.11 KB
/
PBRDemo.cpp
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
//
// Created by 何振邦 on 2020/7/15.
//
#include "Shader.h"
#include "HJGraphics.h"
#include "Log.h"
#include "IBLManager.h"
using namespace std;
using namespace glm;
using namespace HJGraphics;
int main() {
INIT_HJGRAPHICS_LOG
Window window(800,600,"HJGraphics");
glm::vec3 cameraPos=glm::vec3(5.0f,5.0f,10.0f);
glm::vec3 cameraDirection=glm::vec3(0.0f, 0.0f, 0.0f)-cameraPos;
Camera camera(cameraPos,cameraDirection);
auto coord=make_shared<Coordinate>();
// auto skybox=make_shared<Skybox>(25,string("../texture/envmap_miramar/miramar_rt.tga"),
// string("../texture/envmap_miramar/miramar_lf.tga"),
// string("../texture/envmap_miramar/miramar_up.tga"),
// string("../texture/envmap_miramar/miramar_dn.tga"),
// string("../texture/envmap_miramar/miramar_bk.tga"),
// string("../texture/envmap_miramar/miramar_ft.tga"));
auto normalMap="../texture/brickwall_normal.jpg"_normal;
TextureList brickwallTexture{"../texture/brickwall.jpg"_diffuse,normalMap};
auto brickMaterial=make_shared<PBRMaterial>(brickwallTexture);
brickMaterial->reflectable=1.0f;
auto box=make_shared<Box>(2, 2, 2,brickMaterial);
box->model=translate(box->model,vec3(0.0f,0.0f,-2.5f));
auto plane=make_shared<Plane>(8, 8,8, brickMaterial);
auto soliddiffuse=make_shared<SolidTexture>(glm::vec3(0.9,0.9,0.8));
soliddiffuse->usage="diffuse";
TextureList brickwallTexture2{soliddiffuse,normalMap};
//1
//|
//metallic
//|
//|
//0-----------------roughness------------------>1
vector<shared_ptr<Sphere>> spheres;
for(int i=0;i<5;++i){
auto sphereMat=make_shared<PBRMaterial>(brickwallTexture2);
static_pointer_cast<SolidTexture>(sphereMat->roughnessMap)->setColor(i/5.0f+0.1);
static_pointer_cast<SolidTexture>(sphereMat->metallicMap)->setColor(0.9);
auto sphere=make_shared<Sphere>(0.3, 30,sphereMat);
sphere->model=translate(sphere->model,vec3(-2+i,2.5,0));
spheres.push_back(sphere);
}
for(int i=0;i<5;++i){
auto sphereMat=make_shared<PBRMaterial>(brickwallTexture2);
static_pointer_cast<SolidTexture>(sphereMat->roughnessMap)->setColor(i/5.0f+0.1);
static_pointer_cast<SolidTexture>(sphereMat->metallicMap)->setColor(0.6);
auto sphere=make_shared<Sphere>(0.3, 30,sphereMat);
sphere->model=translate(sphere->model,vec3(-2+i,1.8,0));
spheres.push_back(sphere);
}
for(int i=0;i<5;++i){
auto sphereMat=make_shared<PBRMaterial>(brickwallTexture2);
static_pointer_cast<SolidTexture>(sphereMat->roughnessMap)->setColor(i/5.0f+0.1);
static_pointer_cast<SolidTexture>(sphereMat->metallicMap)->setColor(0.35);
auto sphere=make_shared<Sphere>(0.3, 30,sphereMat);
sphere->model=translate(sphere->model,vec3(-2+i,1.1,0));
spheres.push_back(sphere);
}
for(int i=0;i<5;++i){
auto sphereMat=make_shared<PBRMaterial>(brickwallTexture2);
static_pointer_cast<SolidTexture>(sphereMat->roughnessMap)->setColor(i/5.0f+0.1);
static_pointer_cast<SolidTexture>(sphereMat->metallicMap)->setColor(0.1);
auto sphere=make_shared<Sphere>(0.3, 30,sphereMat);
sphere->model=translate(sphere->model,vec3(-2+i,0.4,0));
spheres.push_back(sphere);
auto simpleAnimater=make_shared<DemoSinAnimater>(sphere->model,vec3(0,0,-2),3.0,i);
sphere->animater=simpleAnimater;
}
auto paraLight=make_shared<ParallelLight>(glm::vec3(-1.0f, -0.7f, -2.0f), glm::vec3(4.0f, 4.0f, 0.0f),glm::vec3(2.0f));
auto spotLight=make_shared<SpotLight>(glm::vec3(1.0f, -1.0f, -1.0f), glm::vec3(-5.0f, 5.0f, 3.0f), glm::vec3(3));
auto pointLight=make_shared<PointLight>(glm::vec3(0.0f, 2.0f, 2.0f),glm::vec3(3));
auto scene=make_shared<Scene>(0.3,glm::vec3(0));
scene->addLight(pointLight);
// scene->addLight(spotLight);
// scene->addLight(paraLight);
scene->addCamera(camera);
for(auto& s:spheres)scene->addObject(s);
scene->addObject(plane);
scene->addObject(coord);
scene->setSkybox(50.0f,std::make_shared<Texture2D>("../texture/beach.hdr", Texture2DOption()));
auto renderer=make_shared<DeferredRenderer>(1600,1200);
renderer->setMainScene(scene);
window.renderer=renderer;
window.run();
glfwTerminate();
return 0;
}