In p5.js, there are two render modes: P2D (default renderer) and WebGL. WEBGL enables the user to draw in 3D. There are many ways to implement lighting. Currently, p5js has implemented 8. To add lighting to a 3D object, one can use these functionalities. But there is another technique to light objects, not by direct light, but using the surrounding environment as a single light source, which we call Image-Based lighting. This project aims to add lighting to a 3D object, using the surrounding environment as a single light source, which is generally called Image-Based lighting. In simple words, one can very quickly drop in an image from real life to use as surrounding lights, rather than continuously tweaking the colors and positions of ambient, point, etc lights.
- Diffused IBL
- Create scene's irradiance.
- Calculation of Scene’s irradiance for any direction.
- Sample the scene’s radiance from all possible directions, within the hemisphere, for each fragment.
- Take a finite number of samples of the scene's irradiance and pre-compute them.
- Create a pre-computed irradiance map.
- Sample the pre-computed irradiance map to retrieve diffuse irradiance.
- Specular IBL
- We need to preconvolute it.
- Use split sum approximation to divide the specular part into 2 further parts
- First one is a prefiltered environment map.
- Finalize Pre filter convolution using low discrepancy hammersley sequence and sample generation defined.
- Capturing prefilter mipmap levels, storing the results in prefiltered environment cubemap
- Second one is BDRF
- pre -calculate the BRDF’s response given input as roughness and angle between n and wi. Precalculations done using BRDF’S geometry function and Fresnel-Schlicks approximation.
- Stored in 2D lookup texture known as BRDF integration map.
- First one is a prefiltered environment map.
- Combine the prefiltered environment map and BRDF integration map
- Combine the diffused and specular parts
The project is completed and here are some screenshots and videos demonstrating the work.
example.1.mp4
example.2.mp4
- Pull Request: #6255
- Work Reports:
- This includes the function
imageLight()
which provides the whole functionality. - 2 Examples for the
imageLight()
are also included in this files.
- This includes 2 new maps, which are diffusedTextures and specularTextures for storing the p5 graphics.
- Then the function
getDiffusedTexture()
which gets called from _setImageLightUniforms. It's function is to create a blurry image from the input non blurry img, if it doesn't already exist. - Also the function
getSpecularTexture()
which also gets called from _setImageLightUniforms. It's function is too create a texture from the input non blurry image, if it doesn't already exist - Then the function
_setImageLightUniforms()
. It creates the textures and sets those textures in the shader being processed.
- This includes the
MipmapTexture
class.
- It is a vertex shader only for the image Light feature.
- It is the Fragment shader for the calculations of the Diffused Part of Image Light.
- It is the Fragment shader for the calculations of the Specular Part of Image Light.
- It has the functions
HammersleyNoBitOps()
,VanDerCorput()
andImportanceSampleGGX()
which are referenced from "https://learnopengl.com/PBR/IBL/Specular-IBL"
- This includes
calculateImageDiffuse()
andcalculateImageSpecular()
which actually calculates the output textures. These are calculated only whenimageLight()
is called.
- src/webgl/shaders/basic.frag
- src/webgl/shaders/immediate.vert
- src/webgl/shaders/light.vert
- src/webgl/shaders/light_texture.frag
- src/webgl/shaders/line.frag
- src/webgl/shaders/line.vert
- src/webgl/shaders/normal.frag
- src/webgl/shaders/normal.vert
- src/webgl/shaders/phong.frag
- src/webgl/shaders/phong.vert
- src/webgl/shaders/point.frag
- src/webgl/shaders/point.vert
- src/webgl/shaders/vertexColor.frag
- src/webgl/shaders/vertexColor.vert
- Example 1 in imagelight https://editor.p5js.org/aryan_koundal/sketches/OEsyk6uZI
- Example 2 in imagelight https://editor.p5js.org/aryan_koundal/sketches/XjalPP7s4
- Final Prototype Diffused + Roughness (Variable Roughness) https://editor.p5js.org/aryan_koundal/sketches/4V790dB9Z
- Diffuse light final prototype https://editor.p5js.org/aryan_koundal/sketches/q_Zg37OB2
- Mipmap Specular roughness Prototype (visible variation) https://editor.p5js.org/aryan_koundal/sketches/Bi2BN7zjK
- Specular prefilterconvolution with chessboard https://editor.p5js.org/aryan_koundal/sketches/qaIhxRZHI
- Prefilterconvolution cubemaps prototypes 8 levels https://editor.p5js.org/aryan_koundal/sketches/YJTSFKhqt
- Specular prefilterconvolution with image https://editor.p5js.org/aryan_koundal/sketches/8divJgdQxO
- Specular mipmaps prototype with colors https://editor.p5js.org/aryan_koundal/sketches/3V9iDH8ax
- Sphere with point Lights https://editor.p5js.org/aryan_koundal/sketches/9NdeCtfdW
- Diffused texture Shader Prototype https://editor.p5js.org/aryan_koundal/sketches/DcFDcOFUn
- Resolution Pixelwise https://editor.p5js.org/aryan_koundal/sketches/5RfDIy2I9
- Cube reflecting mountain spheremap https://editor.p5js.org/aryan_koundal/sketches/2QS5-Fy0V
- Cube reflecting sky spheremap https://editor.p5js.org/aryan_koundal/sketches/O1NwI4ufp
While working on this project, I realised that there is scope for improvement. Like increasing efficiency by using cubemaps instead of environment maps for Diffused Lighting. Also using framebuffers would improve the efficiency and reduce the time taken to render the lights.
My GSoC experience was genuinely transformative, leading to significant personal and professional development within the open-source domain. I successfully overcame initial obstacles related to setting up the project and navigating the codebase, steadily advancing through my contributions. Throughout this summer, I actively participated in the p5.js open-source community, surpassing my initial expectations for my first major open-source venture and further igniting my enthusiasm. I want to express my heartfelt appreciation to my mentors, Dave Pagurek(@davepagurek ), and Tanvi Kumar(@TanviKumar ), for their invaluable guidance in navigating coding challenges. Effective teamwork, collaboration, and communication proved essential in this open-source journey. I eagerly anticipate expanding my contributions and honing my skills. This summer has instilled a sense of purpose in me, and I'm profoundly grateful for the mentorship and knowledge gained.