Browse Source

Update models_material_pbr.c

Ray 4 years ago
parent
commit
7e68e733f5
1 changed files with 18 additions and 4 deletions
  1. 18 4
      examples/models/models_material_pbr.c

+ 18 - 4
examples/models/models_material_pbr.c

@@ -279,17 +279,31 @@ static TextureCubemap GenTextureCubemap(Shader shader, Texture2D panorama, int s
 
     rlViewport(0, 0, size, size);   // Set viewport to current fbo dimensions
 
+    // Activate and enable texture for drawing to cubemap faces
+    rlActiveTextureSlot(0);
+    rlEnableTexture(panorama.id);
+
     for (int i = 0; i < 6; i++)
     {
+        // Set the view matrix for the current cube face
         rlSetUniformMatrix(shader.locs[SHADER_LOC_MATRIX_VIEW], fboViews[i]);
+        
+        // Select the current cubemap face attachment for the fbo
+        // WARNING: This function by default enables->attach->disables fbo!!!
         rlFramebufferAttach(fbo, cubemap.id, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_CUBEMAP_POSITIVE_X + i, 0);
-
         rlEnableFramebuffer(fbo);
-        rlSetTexture(panorama.id);   // WARNING: It must be called after enabling current framebuffer if using internal batch system!
 
+        // Load and draw a cube, it uses the current enabled texture
         rlClearScreenBuffers();
-        DrawCubeV(Vector3Zero(), Vector3One(), WHITE);
-        rlDrawRenderBatchActive();
+        rlLoadDrawCube();
+        
+        // ALTERNATIVE: Try to use internal batch system to draw the cube instead of rlLoadDrawCube
+        // for some reason this method does not work, maybe due to cube triangles definition? normals pointing out?
+        // TODO: Investigate this issue...
+        //rlSetTexture(panorama.id); // WARNING: It must be called after enabling current framebuffer if using internal batch system!
+        //rlClearScreenBuffers();
+        //DrawCubeV(Vector3Zero(), Vector3One(), WHITE);
+        //rlDrawRenderBatchActive();
     }
     //------------------------------------------------------------------------------------------