|
@@ -1,6 +1,6 @@
|
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
|
//gl32 --Vlad Luta --
|
|
//gl32 --Vlad Luta --
|
|
|
-//built on 2023-02-18
|
|
|
|
|
|
|
+//built on 2023-02-28
|
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "gl3d.h"
|
|
#include "gl3d.h"
|
|
@@ -31473,7 +31473,9 @@ namespace gl3d
|
|
|
return;
|
|
return;
|
|
|
|
|
|
|
|
setTextureQuality(quality);
|
|
setTextureQuality(quality);
|
|
|
- glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
|
|
+
|
|
|
|
|
+ if(quality > linearNoMipmap)
|
|
|
|
|
+ glGenerateMipmap(GL_TEXTURE_2D);
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -31615,6 +31617,13 @@ namespace gl3d
|
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 1.f);
|
|
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 1.f);
|
|
|
}
|
|
}
|
|
|
break;
|
|
break;
|
|
|
|
|
+ case linearNoMipmap:
|
|
|
|
|
+ {
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
+ glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY, 1.f);
|
|
|
|
|
+ }
|
|
|
|
|
+ break;
|
|
|
case nearestMipmap:
|
|
case nearestMipmap:
|
|
|
{
|
|
{
|
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST_MIPMAP_NEAREST);
|
|
@@ -31894,7 +31903,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
//std::pair< std::string, const char*>{"name", "value"}
|
|
//std::pair< std::string, const char*>{"name", "value"}
|
|
|
//#pragma shaderSources
|
|
//#pragma shaderSources
|
|
|
- std::pair<std::string, const char*>{"ssao.frag", "#version 330 core\n"
|
|
|
|
|
|
|
+ std::pair<std::string, const char*>{"ssao.frag", "#version 330 core\n"
|
|
|
"out float fragColor;\n"
|
|
"out float fragColor;\n"
|
|
|
"noperspective in highp vec2 v_texCoords;\n"
|
|
"noperspective in highp vec2 v_texCoords;\n"
|
|
|
"uniform sampler2D u_gPosition; \n"
|
|
"uniform sampler2D u_gPosition; \n"
|
|
@@ -32691,6 +32700,45 @@ namespace gl3d
|
|
|
"a_outBloom = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
|
"a_outBloom = vec4(0.0, 0.0, 0.0, 1.0);\n"
|
|
|
"};\n"
|
|
"};\n"
|
|
|
"a_outBloom = clamp (a_outBloom, 0.0, 1000.0);\n"
|
|
"a_outBloom = clamp (a_outBloom, 0.0, 1000.0);\n"
|
|
|
|
|
+"}\n"},
|
|
|
|
|
+
|
|
|
|
|
+ std::pair<std::string, const char*>{"colorCorrection.frag", "#version 150\n"
|
|
|
|
|
+"out vec4 a_color;\n"
|
|
|
|
|
+"noperspective in vec2 v_texCoords;\n"
|
|
|
|
|
+"uniform sampler2D u_texture;\n"
|
|
|
|
|
+"uniform sampler2D u_lookup;\n"
|
|
|
|
|
+"void main ()\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"vec4 tmpvar_1;\n"
|
|
|
|
|
+"tmpvar_1 = texture (u_texture, v_texCoords);\n"
|
|
|
|
|
+"int tmpvar_2;\n"
|
|
|
|
|
+"tmpvar_2 = int(floor((64.0 * tmpvar_1.z)));\n"
|
|
|
|
|
+"int tmpvar_3;\n"
|
|
|
|
|
+"tmpvar_3 = min (int(ceil(\n"
|
|
|
|
|
+"(64.0 * tmpvar_1.z)\n"
|
|
|
|
|
+")), 63);\n"
|
|
|
|
|
+"vec2 finalCellPos_4;\n"
|
|
|
|
|
+"ivec2 index2_5;\n"
|
|
|
|
|
+"index2_5.x = (int(mod (tmpvar_2, 8)));\n"
|
|
|
|
|
+"index2_5.y = (tmpvar_2 / 8);\n"
|
|
|
|
|
+"vec2 tmpvar_6;\n"
|
|
|
|
|
+"tmpvar_6 = (((vec2(0.125, 0.125) * tmpvar_1.xy) + (vec2(0.125, 0.125) * \n"
|
|
|
|
|
+"vec2(index2_5)\n"
|
|
|
|
|
+")) + vec2(0.001, 0.001));\n"
|
|
|
|
|
+"finalCellPos_4.x = tmpvar_6.x;\n"
|
|
|
|
|
+"finalCellPos_4.y = (1.0 - tmpvar_6.y);\n"
|
|
|
|
|
+"vec2 finalCellPos_7;\n"
|
|
|
|
|
+"ivec2 index2_8;\n"
|
|
|
|
|
+"index2_8.x = (int(mod (tmpvar_3, 8)));\n"
|
|
|
|
|
+"index2_8.y = (tmpvar_3 / 8);\n"
|
|
|
|
|
+"vec2 tmpvar_9;\n"
|
|
|
|
|
+"tmpvar_9 = (((vec2(0.125, 0.125) * tmpvar_1.xy) + (vec2(0.125, 0.125) * \n"
|
|
|
|
|
+"vec2(index2_8)\n"
|
|
|
|
|
+")) + vec2(0.001, 0.001));\n"
|
|
|
|
|
+"finalCellPos_7.x = tmpvar_9.x;\n"
|
|
|
|
|
+"finalCellPos_7.y = (1.0 - tmpvar_9.y);\n"
|
|
|
|
|
+"a_color.xyz = mix (texture (u_lookup, finalCellPos_4).xyz, texture (u_lookup, finalCellPos_7).xyz, vec3(((64.0 * tmpvar_1.z) - float(tmpvar_2))));\n"
|
|
|
|
|
+"a_color.w = 1.0;\n"
|
|
|
"}\n"},
|
|
"}\n"},
|
|
|
|
|
|
|
|
std::pair<std::string, const char*>{"chromaticAberation.frag", "#version 150\n"
|
|
std::pair<std::string, const char*>{"chromaticAberation.frag", "#version 150\n"
|
|
@@ -36322,9 +36370,10 @@ namespace gl3d
|
|
|
directionalShadows.create(frameBuffer);
|
|
directionalShadows.create(frameBuffer);
|
|
|
spotShadows.create(frameBuffer);
|
|
spotShadows.create(frameBuffer);
|
|
|
pointShadows.create(frameBuffer);
|
|
pointShadows.create(frameBuffer);
|
|
|
- antiAlias.create(x, y, errorReporter, fileOpener);
|
|
|
|
|
|
|
+ antiAlias.create(errorReporter, fileOpener);
|
|
|
adaptiveResolution.create(x, y);
|
|
adaptiveResolution.create(x, y);
|
|
|
copyDepth.create(errorReporter, fileOpener);
|
|
copyDepth.create(errorReporter, fileOpener);
|
|
|
|
|
+ internal.colorCorrection.create(x, y, errorReporter, fileOpener);
|
|
|
|
|
|
|
|
internal.pBRtextureMaker.init(errorReporter, fileOpener);
|
|
internal.pBRtextureMaker.init(errorReporter, fileOpener);
|
|
|
}
|
|
}
|
|
@@ -38654,6 +38703,16 @@ namespace gl3d
|
|
|
internal.ssao.ssao_finalColor_exponent = std::min(std::max(1.f, exponent), 64.f);
|
|
internal.ssao.ssao_finalColor_exponent = std::min(std::max(1.f, exponent), 64.f);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ bool &Renderer3D::colorCorrection()
|
|
|
|
|
+ {
|
|
|
|
|
+ return internal.colorCorrection.colorCorrection;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ ColorLookupTexture &Renderer3D::colorCorrectionTexture()
|
|
|
|
|
+ {
|
|
|
|
|
+ return internal.colorCorrection.currentTexture;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
bool &Renderer3D::bloom()
|
|
bool &Renderer3D::bloom()
|
|
|
{
|
|
{
|
|
|
return this->internal.lightShader.bloom;
|
|
return this->internal.lightShader.bloom;
|
|
@@ -38821,6 +38880,7 @@ namespace gl3d
|
|
|
j["exposure"] = getExposure();
|
|
j["exposure"] = getExposure();
|
|
|
j["normal mapping"] = isNormalMappingEnabeled();
|
|
j["normal mapping"] = isNormalMappingEnabeled();
|
|
|
j["light subscatter"] = isLightSubScatteringEnabeled();
|
|
j["light subscatter"] = isLightSubScatteringEnabeled();
|
|
|
|
|
+ j["colorCorrection"] = colorCorrection();
|
|
|
|
|
|
|
|
//fxaa
|
|
//fxaa
|
|
|
{
|
|
{
|
|
@@ -38906,6 +38966,12 @@ namespace gl3d
|
|
|
setExposure(exposure);
|
|
setExposure(exposure);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ auto colorCorrection = rez["colorCorrection"];
|
|
|
|
|
+ if (colorCorrection.is_number())
|
|
|
|
|
+ {
|
|
|
|
|
+ this->colorCorrection() = colorCorrection;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
auto normalMapping = rez["normal mapping"];
|
|
auto normalMapping = rez["normal mapping"];
|
|
|
if (normalMapping.is_boolean())
|
|
if (normalMapping.is_boolean())
|
|
|
{
|
|
{
|
|
@@ -39592,6 +39658,19 @@ namespace gl3d
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+ ColorLookupTexture Renderer3D::loadColorLookupTextureFromFile(const char *path)
|
|
|
|
|
+ {
|
|
|
|
|
+ GpuTexture gpuTexture;
|
|
|
|
|
+ gpuTexture.loadTextureFromFile(path, fileOpener, -1, 3);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, gpuTexture.id);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
|
|
|
|
+
|
|
|
|
|
+ return {gpuTexture.id};
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
void Renderer3D::render(float deltaTime)
|
|
void Renderer3D::render(float deltaTime)
|
|
|
{
|
|
{
|
|
|
glEnable(GL_DEPTH_TEST);
|
|
glEnable(GL_DEPTH_TEST);
|
|
@@ -40010,7 +40089,7 @@ namespace gl3d
|
|
|
{
|
|
{
|
|
|
if (!(potentialAnimations && j.hasBones))
|
|
if (!(potentialAnimations && j.hasBones))
|
|
|
{
|
|
{
|
|
|
- if (shouldCullObject(j.minBoundary, j.maxBoundary, modelViewProjMat))
|
|
|
|
|
|
|
+ if (frustumCulling && shouldCullObject(j.minBoundary, j.maxBoundary, modelViewProjMat))
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -40525,18 +40604,14 @@ namespace gl3d
|
|
|
internal.directionalLights[lightIndex].changedThisFrame = false;
|
|
internal.directionalLights[lightIndex].changedThisFrame = false;
|
|
|
|
|
|
|
|
glm::vec3 lightDir = internal.directionalLights[lightIndex].direction;
|
|
glm::vec3 lightDir = internal.directionalLights[lightIndex].direction;
|
|
|
- //glm::mat4 lightView = lookAtSafe(-lightDir, {}, { 0.f,1.f,0.f });
|
|
|
|
|
|
|
|
|
|
glm::vec3 direction = lightDir;
|
|
glm::vec3 direction = lightDir;
|
|
|
glm::vec3 eye = camera.position - (direction);
|
|
glm::vec3 eye = camera.position - (direction);
|
|
|
glm::vec3 center = eye + direction;
|
|
glm::vec3 center = eye + direction;
|
|
|
|
|
|
|
|
- glm::mat4 lightView = lookAtSafe(eye, center, { 0.f,1.f,0.f });
|
|
|
|
|
- //glm::mat4 lightView = lookAtSafe(camera.position, camera.position + lightDir, { 0.f,1.f,0.f });
|
|
|
|
|
|
|
+ glm::mat4 lightView = lookAtSafe(eye, center, {0.f,1.f,0.f});//todo option to add a custom vector direction
|
|
|
|
|
|
|
|
//zoffset is used to move the light further
|
|
//zoffset is used to move the light further
|
|
|
-
|
|
|
|
|
-
|
|
|
|
|
float zOffsets[] = { 15 / 200.f,0,0 };
|
|
float zOffsets[] = { 15 / 200.f,0,0 };
|
|
|
|
|
|
|
|
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
glFramebufferTextureLayer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT,
|
|
@@ -41702,7 +41777,16 @@ namespace gl3d
|
|
|
#pragma region draw to screen and fxaa
|
|
#pragma region draw to screen and fxaa
|
|
|
|
|
|
|
|
glViewport(0, 0, internal.w, internal.h);
|
|
glViewport(0, 0, internal.w, internal.h);
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
|
|
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ if (colorCorrection())
|
|
|
|
|
+ {
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, internal.colorCorrection.fbo);
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
if (antiAlias.usingFXAA || adaptiveResolution.useAdaptiveResolution)
|
|
if (antiAlias.usingFXAA || adaptiveResolution.useAdaptiveResolution)
|
|
|
{
|
|
{
|
|
@@ -41737,8 +41821,28 @@ namespace gl3d
|
|
|
|
|
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
|
|
|
|
|
|
|
|
+ #pragma region color corection
|
|
|
|
|
+
|
|
|
|
|
+ if (colorCorrection())
|
|
|
|
|
+ {
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
|
|
|
|
|
|
|
|
|
|
+ internal.colorCorrection.shader.bind();
|
|
|
|
|
+ glUniform1i(internal.colorCorrection.u_texture, 0);
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.colorCorrection.texture);
|
|
|
|
|
|
|
|
|
|
+ glUniform1i(internal.colorCorrection.u_lookup, 1);
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE1);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.colorCorrection.currentTexture.t.id);
|
|
|
|
|
+
|
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ #pragma endregion
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ //todo implement
|
|
|
#pragma region copy depth buffer for later forward rendering
|
|
#pragma region copy depth buffer for later forward rendering
|
|
|
|
|
|
|
|
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
|
|
glBindFramebuffer(GL_FRAMEBUFFER, frameBuffer);
|
|
@@ -41804,7 +41908,8 @@ namespace gl3d
|
|
|
postProcess.resize(internal.adaptiveW, internal.adaptiveH);
|
|
postProcess.resize(internal.adaptiveW, internal.adaptiveH);
|
|
|
|
|
|
|
|
adaptiveResolution.resize(internal.adaptiveW, internal.adaptiveH);
|
|
adaptiveResolution.resize(internal.adaptiveW, internal.adaptiveH);
|
|
|
-
|
|
|
|
|
|
|
+
|
|
|
|
|
+ internal.colorCorrection.resize(x, y);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void Renderer3D::clearAllLoadedResource()
|
|
void Renderer3D::clearAllLoadedResource()
|
|
@@ -41899,6 +42004,7 @@ namespace gl3d
|
|
|
adaptiveResolution.clear();
|
|
adaptiveResolution.clear();
|
|
|
internal.pBRtextureMaker.clear();
|
|
internal.pBRtextureMaker.clear();
|
|
|
copyDepth.clear();
|
|
copyDepth.clear();
|
|
|
|
|
+ internal.colorCorrection.clear();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
SkyBox Renderer3D::loadSkyBox(const char *names[6])
|
|
SkyBox Renderer3D::loadSkyBox(const char *names[6])
|
|
@@ -42512,7 +42618,7 @@ namespace gl3d
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
- void Renderer3D::AntiAlias::create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener)
|
|
|
|
|
|
|
+ void Renderer3D::AntiAlias::create(ErrorReporter &errorReporter, FileOpener &fileOpener)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
shader.loadShaderProgramFromFile("shaders/drawQuads.vert",
|
|
shader.loadShaderProgramFromFile("shaders/drawQuads.vert",
|
|
@@ -42839,6 +42945,54 @@ namespace gl3d
|
|
|
shader.clear();
|
|
shader.clear();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void Renderer3D::ColorCorrection::create(int w, int h, ErrorReporter &errorReporter, FileOpener &fileOpener)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ shader.loadShaderProgramFromFile("shaders/drawQuads.vert", "shaders/postProcess/colorCorrection.frag", errorReporter, fileOpener);
|
|
|
|
|
+
|
|
|
|
|
+ u_texture = getUniform(shader.id, "u_texture", errorReporter);
|
|
|
|
|
+ u_lookup = getUniform(shader.id, "u_lookup", errorReporter);
|
|
|
|
|
+
|
|
|
|
|
+ glGenFramebuffers(1, &fbo);
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, fbo);
|
|
|
|
|
+ glGenTextures(1, &texture);
|
|
|
|
|
+
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 1, 1, 0, GL_RGBA, GL_FLOAT, NULL);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
|
|
|
|
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
|
|
|
|
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, texture, 0);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ resize(w, h);
|
|
|
|
|
+
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, this->fbo);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void Renderer3D::ColorCorrection::resize(int w, int h)
|
|
|
|
|
+ {
|
|
|
|
|
+ if (currentDimensions.x != w || currentDimensions.y != h)
|
|
|
|
|
+ {
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, texture);
|
|
|
|
|
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h,
|
|
|
|
|
+ 0, GL_RGBA, GL_FLOAT, NULL);
|
|
|
|
|
+
|
|
|
|
|
+ currentDimensions = glm::ivec2(w, h);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ void Renderer3D::ColorCorrection::clear()
|
|
|
|
|
+ {
|
|
|
|
|
+ glDeleteFramebuffers(1, &fbo);
|
|
|
|
|
+ glDeleteTextures(1, &texture);
|
|
|
|
|
+ shader.clear();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
};
|
|
};
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
|
|
|
|