28 if (sourceTexture !=
nullptr)
57 shaderPath +
"PBR_CubeMap.vert",
58 shaderPath +
"PBR_CylinderToCubeMap.frag");
61 shaderPath +
"PBR_CubeMap.vert",
62 shaderPath +
"PBR_IrradianceConvolution.frag");
65 shaderPath +
"PBR_CubeMap.vert",
66 shaderPath +
"PBR_PrefilterRoughness.frag");
69 shaderPath +
"PBR_BRDFIntegration.vert",
70 shaderPath +
"PBR_BRDFIntegration.frag");
117 bool saveReadbackTextures =
false;
119 glGenTextures(1, &
_texID);
123 glGenFramebuffers(1, &fboID);
126 glGenRenderbuffers(1, &rboID);
135 for (
SLuint i = 0; i < 6; i++)
137 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
161 glActiveTexture(GL_TEXTURE0 + texUnit);
165 glBindFramebuffer(GL_FRAMEBUFFER, fboID);
166 glBindRenderbuffer(GL_RENDERBUFFER, rboID);
167 glRenderbufferStorage(GL_RENDERBUFFER, GL_DEPTH_COMPONENT24,
_width,
_height);
168 glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rboID);
173 GLenum DrawBuffers[1] = {GL_COLOR_ATTACHMENT0};
174 glDrawBuffers(1, DrawBuffers);
176 for (
SLuint i = 0; i < 6; i++)
181 glFramebufferTexture2D(GL_FRAMEBUFFER,
182 GL_COLOR_ATTACHMENT0,
183 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
187 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
193 ?
"environmentCubemap_side"
194 :
"irradianceCubemap_side";
195 name += std::to_string(i) +
".png";
199 saveReadbackTextures);
203 glBindFramebuffer(GL_FRAMEBUFFER, 0);
204 glBindRenderbuffer(GL_RENDERBUFFER, 0);
208 glBindTexture(GL_TEXTURE_CUBE_MAP,
_texID);
209 glGenerateMipmap(GL_TEXTURE_CUBE_MAP);
215 "the source texture is not an environment map");
220 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
221 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
222 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
223 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR);
224 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
225 glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_BASE_LEVEL, 0);
235 for (
SLint i = 0; i < 6; i++)
237 glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
257 glActiveTexture(GL_TEXTURE0 + texUnit);
265 glViewport(0, 0, mipWidth, mipHeight);
267 glBindFramebuffer(GL_FRAMEBUFFER, fboID);
272 for (
SLuint i = 0; i < 6; ++i)
276 glFramebufferTexture2D(GL_FRAMEBUFFER,
277 GL_COLOR_ATTACHMENT0,
278 GL_TEXTURE_CUBE_MAP_POSITIVE_X + i,
282 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
290 string name =
"roughnessCubemap_mip" +
291 std::to_string(mipLevel) +
"_side" +
292 std::to_string(i) +
".png";
296 saveReadbackTextures);
300 glBindFramebuffer(GL_FRAMEBUFFER, 0);
322 glBindFramebuffer(GL_FRAMEBUFFER, fboID);
324 glFramebufferTexture2D(GL_FRAMEBUFFER,
325 GL_COLOR_ATTACHMENT0,
335 glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
343 string name =
"brdfLUT.png";
347 saveReadbackTextures);
350 glBindFramebuffer(GL_FRAMEBUFFER, 0);
353 glDeleteFramebuffers(1, &fboID);
354 glDeleteRenderbuffers(1, &rboID);
359 glViewport(vp.x, vp.y, vp.z, vp.w);
426 glBindBuffer(GL_ARRAY_BUFFER,
_cubeVBO);
427 glBufferData(GL_ARRAY_BUFFER,
sizeof(vertices), vertices, GL_STATIC_DRAW);
431 glEnableVertexAttribArray(0);
432 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 3 *
sizeof(
float), (
void*)0);
433 glBindBuffer(GL_ARRAY_BUFFER, 0);
434 glBindVertexArray(0);
439 glDrawArrays(GL_TRIANGLES, 0, 36);
440 glBindVertexArray(0);
450 float quadVertices[] = {
452 -1.0f, 1.0f, 0.0f, 0.0f, 1.0f,
453 -1.0f, -1.0f, 0.0f, 0.0f, 0.0f,
454 1.0f, 1.0f, 0.0f, 1.0f, 1.0f,
455 1.0f, -1.0f, 0.0f, 1.0f, 0.0f,
463 glBindBuffer(GL_ARRAY_BUFFER,
_quadVBO);
464 glBufferData(GL_ARRAY_BUFFER,
sizeof(quadVertices), &quadVertices, GL_STATIC_DRAW);
465 glEnableVertexAttribArray(0);
466 glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, 5 *
sizeof(
float), (
void*)0);
467 glEnableVertexAttribArray(1);
468 glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, 5 *
sizeof(
float), (
void*)(3 *
sizeof(
float)));
473 glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
474 glBindVertexArray(0);
505 #if defined(DEBUG) || defined(_DEBUG)
506 GLenum fbStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
509 case GL_FRAMEBUFFER_COMPLETE:
break;
510 case GL_FRAMEBUFFER_UNDEFINED:
SL_LOG(
"**** GL_FRAMEBUFFER_UNDEFINED ****");
break;
511 case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:
SL_LOG(
"**** GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT ****");
break;
512 case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:
SL_LOG(
"GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT ****");
break;
513 case GL_FRAMEBUFFER_UNSUPPORTED:
SL_LOG(
"**** GL_FRAMEBUFFER_UNSUPPORTED ****");
break;
514 case GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE:
SL_LOG(
"**** GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE ****");
break;
518 default:
SL_LOG(
"Unknown framebuffer status!!!");
#define SL_BRDF_LUT_GL_INTERNAL_FORMAT
#define SL_HDR_PIXEL_BYTES
SLTextureType
Texture type enumeration & their filename appendix for auto type detection.
#define SL_READ_PIXELS_CV_FORMAT
#define SL_BRDF_LUT_GL_FORMAT
#define SL_HDR_GL_INTERNAL_FORMAT
#define SL_BRDF_LUT_GL_TYPE
#define SL_READ_PIXELS_GL_FORMAT
#define SL_BRDF_LUT_PIXEL_BYTES
const SLint ROUGHNESS_NUM_MIP_LEVELS
OpenCV image class with the same interface as the former SLImage class.
void savePNG(const string &filename, int compressionLevel=6, bool flipY=true, bool convertBGR2RGB=true)
Save as PNG at a certain compression level (0-9)
Toplevel holder of the assets meshes, materials, textures and shaders.
SLVGLTexture & textures()
Generic Shader Program class inherited from SLGLProgram.
SLint uniformMatrix4fv(const SLchar *name, SLsizei count, const SLfloat *value, GLboolean transpose=false) const
Passes a 4x4 float matrix values py pointer to the uniform variable "name".
SLint uniform1f(const SLchar *name, SLfloat v0) const
Passes the float value v0 to the uniform variable "name".
SLint uniform1i(const SLchar *name, SLint v0) const
Passes the int values v0 to the uniform variable "name".
Singleton class holding all OpenGL states.
void viewport(SLint x, SLint y, SLsizei width, SLsizei height)
static SLGLState * instance()
Public static instance getter for singleton pattern.
Texture object for OpenGL texturing.
SLbool _resizeToPow2
Flag if image should be resized to n^2.
void deleteImages()
Deletes the CVImages in _images. No more texture mapping in ray tracing.
SLint _bytesPerPixel
Bytes per texture image pixel (images exist either in _images or on the GPU or on both)
SLint _width
Texture image width in pixels (images exist either in _images or on the GPU or on both)
SLfloat _bumpScale
Bump mapping scale factor.
SLuint _bytesOnGPU
NO. of bytes on GPU.
SLint _wrap_t
Wrapping in t direction.
SLint _min_filter
Minification filter.
SLint _wrap_s
Wrapping in s direction.
SLbool _deleteImageAfterBuild
Flag if images should be deleted after build on GPU.
SLint _height
Texture image height in pixels (images exist either in _images or on the GPU or on both)
SLTextureType _texType
See SLTextureType.
void deleteData(SLbool deleteAlsoOnGPU)
Delete all data (CVImages and GPU textures)
CVVImage _images
Vector of CVImage pointers.
SLenum _target
texture target
SLstring typeName()
Returns the texture type as string.
std::atomic< bool > _needsUpdate
Flag if image needs an single update.
SLint _internalFormat
Internal OpenGL format.
void texType(SLTextureType bt)
SLint _mag_filter
Magnification filter.
void bindActive(SLuint texUnit=0)
SLbool _autoCalcTM3D
Flag if texture matrix should be calculated from AABB for 3D mapping.
SLuint _texID
OpenGL texture ID.
SLGLProgram * _shaderProgram
Shader program to render the texture.
SLVMat4f _captureViews
All 6 positions of the views that represent the 6 sides of the cube map.
virtual ~SLGLTextureIBL()
SLGLTexture * _sourceTexture
2D Texture from the HDR Image
virtual void build(SLint texID=0)
void renderQuad()
Renders a 2x2 XY quad, used for rendering and capturing the BRDF integral.
SLMat4f _captureProjection
Projection matrix for capturing the textures.
SLGLTextureIBL()
Default constructor.
void logFramebufferStatus()
void renderCube()
Renders 2x2 cube, used to project a texture to a cube texture with 6 sides.
void readPixels(int width, int height, string name, bool savePNG)
Reads back the pixels into an image.
SLbool _readBackPixels
Flag if generated texture should be read back from GPU into cvMat.
void lookAt(T EyeX, T EyeY, T EyeZ, T AtX=0, T AtY=0, T AtZ=0, T UpX=0, T UpY=0, T UpZ=0)
Defines the a view matrix as the corresponding gluLookAt function.
void perspective(T fov, T aspect, T n, T f)
Defines a perspective projection matrix with a field of view angle.
const SLstring & name() const