Adds HDRI-based Image-Based Lighting (IBL) ambient term to the OpenGL rasterizer - #100
Merged
Merged
Conversation
12 tasks
Member
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Pull Request Template
Description
Adds HDRI-based Image-Based Lighting (IBL) ambient term to the OpenGL rasterizer, plus a tunable flat ambient fallback for scenes with no HDRI loaded. Fixes the raster preview looking flat/dark and lit only by manually placed point lights.
Type of Change
Changes Made
.hdr) equirectangular texture loading (Texture::genTextureHDR,GPUTexture::uploadFloat)IBLProbe(IBL/ibl_probe.hpp/.cpp): converts an equirectangular HDR image to a cubemap, then convolves it into a diffuse irradiance cubemapresources/equirect_to_cubemap.vs/.fs,resources/irradiance_convolve.vs/.fs)resources/equirect_skybox.vs/.fs) andCubeMap::buildHDR()to render an HDRI directly as a background without a full cubemap conversionfungt_default.fs: newirradianceMap,hasIBL,iblIntensityuniforms; ambient term now samples real HDRI-derived irradiance instead of a flat0.05 * material.ambienthack when an environment is loadedambientColoruniform/default (SceneManager-owned) as the fallback ambient term when no HDRI environment is loadedfungt_default.fs's final output, since HDR irradiance/light values can exceed 1.0 and would otherwise hard-clip to whiteSceneManager::loadEnvironment(hdrPath)builds and owns anIBLProbe, binding its irradiance map and settinghasIBL/iblIntensity/ambientColoruniforms once per frame inrenderScene()GPUTexture/OpenGLTexturewithallocateEmptyCubemap()for render-target cubemap allocationIBLProbeto useGPUBuffer(cube mesh) andGPUTexture/Texture(cubemap allocation) instead of raw OpenGL calls, consistent with the existing rendering abstraction layer; offscreen FBO/RBO calls for the two convolution passes remain raw OpenGL (no existing interface covers per-face cubemap render targets)OpenGLTexture::upload()setGL_TEXTURE_MAG_FILTERto a mipmap filter mode (only valid forMIN_FILTER) and never calledglGenerateMipmap; corrected and added the missing mipmap generation callglValidateProgramfailures:texture_diffuse1(sampler2D) andirradianceMap(samplerCube) could both default to texture unit 0; both are now explicitly pinned to distinct units at shader link timeSimpleGeometry'sSphereandPlaneprimitives from the separateprimitive_vs.glsl/primitive_fs.glslshader pair tofungt_default.vs/.fs, so they pick up the same ambient/IBL/tonemap behavior as loaded models (vertex layouts were confirmed compatible)Technical Details
texture()) inside an offscreen FBO pass produced wildly inconsistent, sometimes blown-out brightness across cubemap faces, because automatic mip selection has no meaningful screen-space derivatives in that context; switched to explicittextureLod(..., 0.0)SceneManager::setIBLIntensity,setAmbientColor) rather than hardcoded, since raw HDRI irradiance values are frequently too dim or too bright to use directly against arbitrary scene contentresources/cube.vs/.fs) was intentionally left unchanged: it has no vertex normal data end-to-end (geometry generation never emits normals), so it cannot support the lighting model used byfungt_default.fswithout additional geometry-side work; scoped out of this PRTesting
Verified via a dedicated test sample (
Samples/hdr_test) against two HDRIs (a sunny daytime environment and a night environment) and multiple test models (an OBJ/MTL street asset, an FBX street asset). Confirmed via direct GPU texture readback (glGetTexImage) that the generated cubemap and irradiance map contain correct, non-garbage HDR data before and after thetextureLodfix. Confirmed the flat-ambient fallback and IBL path both respond correctly to their respective intensity/color controls.Screenshots / Results
Performance Impact
loadEnvironment()call time, not per-frame)Related Issues
Closes #
Checklist
Notes for Reviewers
resources/cube.vs/.fs) still uses the old unlit/no-normal shader; fixing it requires adding normal generation toGeometries/cube.cppfirst and is left as follow-up work