Skip to content

Commit 04bd781

Browse files
authored
Bugfix Cubemap PBR for mobile devices (#7674)
#changelog #gl
1 parent 7da0987 commit 04bd781

6 files changed

Lines changed: 333 additions & 187 deletions

File tree

examples/gl/materialPBR/src/main.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,21 @@
33

44
//========================================================================
55
int main( ){
6-
6+
// PBR only works with the programmable renderer
7+
#ifdef TARGET_EMSCRIPTEN
8+
ofGLESWindowSettings settings;
9+
settings.glesVersion = 3;
10+
#else
711
//Use ofGLFWWindowSettings for more options like multi-monitor fullscreen
812
ofGLWindowSettings settings;
913
settings.setSize(1200, 768);
10-
// PBR Materials only work with programmable renderer
1114
settings.setGLVersion(3,2);
12-
settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN
15+
#endif
1316

17+
settings.windowMode = OF_WINDOW; //can also be OF_FULLSCREEN
1418
auto window = ofCreateWindow(settings);
1519

1620
ofRunApp(window, std::make_shared<ofApp>());
1721
ofRunMainLoop();
18-
22+
1923
}

examples/gl/materialPBR/src/ofApp.cpp

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
//--------------------------------------------------------------
44
void ofApp::setup(){
5+
// ofSetLogLevel(OF_LOG_VERBOSE);
6+
57
ofSetVerticalSync(false);
68

79
camera.setNearClip(200);
@@ -10,23 +12,43 @@ void ofApp::setup(){
1012
// loading a cube map will enable image based lighting on PBR materials.
1113
// cube map will create a prefiltered light cube map and an irradiance cube map
1214
// cube map texture from https://polyhaven.com
13-
#ifdef USE_CUBE_MAP
15+
#ifdef USE_CUBE_MAP
1416
// comment out the loading of the cube map image to see added cube map lighting without image
1517
// fake environment lighting is added in the pbr shader
16-
cubeMap.load("modern_buildings_2_1k.exr", 512, true );
17-
#endif
18+
19+
ofCubeMap::ofCubeMapSettings csettings;
20+
csettings.filePath = "modern_buildings_2_1k.exr";
21+
// uncomment to load from a cache or make one if it doesn't exist
22+
// csettings.useCache = true;
23+
24+
// uncomment to use the maximum precision available. OpenGL ES is float16 and OpenGL is float32;
25+
// csettings.useMaximumPrecision = true;
26+
27+
// make sure the defaults are the same for making and loading the cache
28+
// ie opengl es defaults are smaller and the file names to load are based on the resolution
29+
csettings.irradianceRes = 32;
30+
csettings.preFilterRes = 128;
31+
32+
cubeMap.load(csettings);
33+
// below is another method for loading a cube map without passing settings class
34+
// cubeMap.load("modern_buildings_2_1k.exr", 512, true );
35+
#endif
36+
37+
ofEnableArbTex();
1838
}
1939

2040
//--------------------------------------------------------------
2141
void ofApp::update(){
22-
42+
prefilterRoughness = ofMap( ofGetMouseX(), 0, ofGetWidth(), 0.0f, 1.0f, true );
2343
}
2444

2545
//--------------------------------------------------------------
2646
void ofApp::draw(){
2747

2848
ofEnableDepthTest();
49+
2950
camera.begin();
51+
3052
float tradius = 50.0;
3153
int numCols = 5;
3254
int numRows = 3;
@@ -73,7 +95,7 @@ void ofApp::draw(){
7395
// this will allow for the benefit of depth clipping
7496
if( cubeMapMode == 2 ) {
7597
if( cubeMap.hasPrefilteredMap() ) {
76-
cubeMap.drawPrefilteredCube(0.25f);
98+
cubeMap.drawPrefilteredCube(prefilterRoughness);
7799
} else {
78100
ofLogNotice("DOES NOT HAVE PRE FILTERED CUBE MAP") << " " << ofGetFrameNum();
79101
}
@@ -94,7 +116,7 @@ void ofApp::draw(){
94116
stringstream ss;
95117
string cmMode = "Cube Map";
96118
if( cubeMapMode == 2 ) {
97-
cmMode = "Prefiltered";
119+
cmMode = "Prefiltered : roughness(mouse): " + ofToString(prefilterRoughness,2);
98120
} else if(cubeMapMode == 3 ) {
99121
cmMode = "Irradiance";
100122
}

examples/gl/materialPBR/src/ofApp.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ class ofApp : public ofBaseApp{
3030
#endif
3131

3232
int cubeMapMode = 1;
33+
float prefilterRoughness = 0.25;
3334

3435
};

0 commit comments

Comments
 (0)