|
@@ -1,6 +1,6 @@
|
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
|
//gl32 --Vlad Luta --
|
|
//gl32 --Vlad Luta --
|
|
|
-//built on 2022-11-22
|
|
|
|
|
|
|
+//built on 2023-01-23
|
|
|
////////////////////////////////////////////////
|
|
////////////////////////////////////////////////
|
|
|
|
|
|
|
|
#include "gl3d.h"
|
|
#include "gl3d.h"
|
|
@@ -31291,11 +31291,12 @@ void gl3d::ErrorReporter::callErrorCallback(std::string s)
|
|
|
|
|
|
|
|
void gl3d::defaultErrorCallback(std::string err, void *userData)
|
|
void gl3d::defaultErrorCallback(std::string err, void *userData)
|
|
|
{
|
|
{
|
|
|
|
|
+ //std::cout << err << "\n";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::string gl3d::defaultReadEntireFile(const char* fileName, bool &couldNotOpen, void *userData)
|
|
std::string gl3d::defaultReadEntireFile(const char* fileName, bool &couldNotOpen, void *userData)
|
|
|
{
|
|
{
|
|
|
- return {};
|
|
|
|
|
|
|
+ return "";
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
std::vector<char> gl3d::defaultReadEntireFileBinary(const char *fileName, bool &couldNotOpen, void *userData)
|
|
std::vector<char> gl3d::defaultReadEntireFileBinary(const char *fileName, bool &couldNotOpen, void *userData)
|
|
@@ -31305,7 +31306,7 @@ std::vector<char> gl3d::defaultReadEntireFileBinary(const char *fileName, bool &
|
|
|
|
|
|
|
|
bool gl3d::defaultFileExists(const char *fileName, void *userData)
|
|
bool gl3d::defaultFileExists(const char *fileName, void *userData)
|
|
|
{
|
|
{
|
|
|
- return {};
|
|
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
@@ -31814,12 +31815,13 @@ 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"
|
|
|
"uniform isampler2D u_gNormal;\n"
|
|
"uniform isampler2D u_gNormal;\n"
|
|
|
"uniform sampler2D u_texNoise;\n"
|
|
"uniform sampler2D u_texNoise;\n"
|
|
|
|
|
+"uniform sampler2D u_depthBuffer;\n"
|
|
|
"uniform vec3 samples[64];\n"
|
|
"uniform vec3 samples[64];\n"
|
|
|
"uniform mat4 u_projection; \n"
|
|
"uniform mat4 u_projection; \n"
|
|
|
"uniform mat4 u_view; \n"
|
|
"uniform mat4 u_view; \n"
|
|
@@ -31838,14 +31840,29 @@ namespace gl3d
|
|
|
"ret -= 1.f;\n"
|
|
"ret -= 1.f;\n"
|
|
|
"return normalize(ret);\n"
|
|
"return normalize(ret);\n"
|
|
|
"}\n"
|
|
"}\n"
|
|
|
|
|
+"uniform float u_farPlane;\n"
|
|
|
|
|
+"uniform float u_closePlane;\n"
|
|
|
|
|
+"vec3 viewSpace(vec2 vTexCoord)\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"float z = texture2D(u_depthBuffer, vTexCoord).x; \n"
|
|
|
|
|
+"float z_n = 2.0 * z - 1.0;\n"
|
|
|
|
|
+"float z_e = 2.0 * u_closePlane * u_farPlane / (u_farPlane + u_closePlane - z_n * (u_farPlane - u_closePlane));\n"
|
|
|
|
|
+"vec3 retVector = vec3(1,1,1);\n"
|
|
|
|
|
+"return retVector * z_e;\n"
|
|
|
|
|
+"float x = vTexCoord.x * 2 - 1;\n"
|
|
|
|
|
+"float y = (1 - vTexCoord.y) * 2 - 1;\n"
|
|
|
|
|
+"vec4 vProjectedPos = vec4(x, y, z, 1.0f);\n"
|
|
|
|
|
+"vec4 vPositionVS = inverse(u_projection) * vProjectedPos; \n"
|
|
|
|
|
+"return vPositionVS.xyz / vPositionVS.w; \n"
|
|
|
|
|
+"}\n"
|
|
|
"void main()\n"
|
|
"void main()\n"
|
|
|
"{\n"
|
|
"{\n"
|
|
|
"vec2 screenSize = textureSize(u_gPosition, 0).xy/2.f; \n"
|
|
"vec2 screenSize = textureSize(u_gPosition, 0).xy/2.f; \n"
|
|
|
"vec2 noiseScale = vec2(screenSize.x/4.0, screenSize.y/4.0);\n"
|
|
"vec2 noiseScale = vec2(screenSize.x/4.0, screenSize.y/4.0);\n"
|
|
|
"vec2 noisePos = v_texCoords * noiseScale;\n"
|
|
"vec2 noisePos = v_texCoords * noiseScale;\n"
|
|
|
"vec3 fragPos = texture(u_gPosition, v_texCoords).xyz;\n"
|
|
"vec3 fragPos = texture(u_gPosition, v_texCoords).xyz;\n"
|
|
|
-"vec3 normal = vec3(transpose(inverse(mat3(u_view))) * \n"
|
|
|
|
|
-"fromuShortToFloat(texture(u_gNormal, v_texCoords).xyz));\n"
|
|
|
|
|
|
|
+"vec3 normal = normalize( vec3(transpose(inverse(mat3(u_view))) * \n"
|
|
|
|
|
+"fromuShortToFloat(texture(u_gNormal, v_texCoords).xyz)) );\n"
|
|
|
"vec3 randomVec = texture2D(u_texNoise, noisePos).xyz; \n"
|
|
"vec3 randomVec = texture2D(u_texNoise, noisePos).xyz; \n"
|
|
|
"vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));\n"
|
|
"vec3 tangent = normalize(randomVec - normal * dot(randomVec, normal));\n"
|
|
|
"vec3 bitangent = cross(normal, tangent);\n"
|
|
"vec3 bitangent = cross(normal, tangent);\n"
|
|
@@ -32731,6 +32748,83 @@ namespace gl3d
|
|
|
"float roughness = texture(u_roughness, v_texCoords).r;\n"
|
|
"float roughness = texture(u_roughness, v_texCoords).r;\n"
|
|
|
"float ambient = texture(u_ambient, v_texCoords).r;\n"
|
|
"float ambient = texture(u_ambient, v_texCoords).r;\n"
|
|
|
"fragColor = vec4(roughness, metallic, ambient, 1);\n"
|
|
"fragColor = vec4(roughness, metallic, ambient, 1);\n"
|
|
|
|
|
+"}\n"},
|
|
|
|
|
+
|
|
|
|
|
+ std::pair<std::string, const char*>{"hbao.frag", "#version 330 core\n"
|
|
|
|
|
+"out float fragColor;\n"
|
|
|
|
|
+"noperspective in highp vec2 v_texCoords;\n"
|
|
|
|
|
+"uniform sampler2D u_gPosition;\n"
|
|
|
|
|
+"uniform isampler2D u_gNormal;\n"
|
|
|
|
|
+"uniform sampler2D u_texNoise;\n"
|
|
|
|
|
+"uniform mat4 u_projection; \n"
|
|
|
|
|
+"uniform mat4 u_view; \n"
|
|
|
|
|
+"const float INFINITY = 1.f/0.f;\n"
|
|
|
|
|
+"vec3 fromuShortToFloat(ivec3 a)\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"vec3 ret = a;\n"
|
|
|
|
|
+"ret /= 65536;\n"
|
|
|
|
|
+"ret *= 2.f;\n"
|
|
|
|
|
+"ret -= 1.f;\n"
|
|
|
|
|
+"return normalize(ret);\n"
|
|
|
|
|
+"}\n"
|
|
|
|
|
+"float saturate(float a)\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"return min(max(a,0),1);\n"
|
|
|
|
|
+"}\n"
|
|
|
|
|
+"vec2 computeAO(vec3 normal, vec2 direction, vec2 screenSize, vec3 fragPos)\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"float RAD = 0.05;\n"
|
|
|
|
|
+"float RAD_FOR_DIRECTION = length( direction*vec2(10.0) / (vec2(abs(fragPos.z))*screenSize));\n"
|
|
|
|
|
+"vec3 viewVector = normalize(fragPos);\n"
|
|
|
|
|
+"vec3 leftDirection = cross(viewVector, vec3(direction,0));\n"
|
|
|
|
|
+"vec3 projectedNormal = normal - dot(leftDirection, normal) * leftDirection;\n"
|
|
|
|
|
+"float projectedLen = length(projectedNormal);\n"
|
|
|
|
|
+"projectedNormal /= projectedLen;\n"
|
|
|
|
|
+"vec3 tangent = cross(projectedNormal, leftDirection);\n"
|
|
|
|
|
+"const float bias = (3.141592/360)*20.f;\n"
|
|
|
|
|
+"float tangentAngle = atan(tangent.z / length(tangent.xy));\n"
|
|
|
|
|
+"float sinTangentAngle = sin(tangentAngle + bias);\n"
|
|
|
|
|
+"vec2 texelSize = vec2(1.f,1.f) / screenSize;\n"
|
|
|
|
|
+"float highestZ = -INFINITY;\n"
|
|
|
|
|
+"vec3 foundPos = vec3(0,0,-INFINITY);\n"
|
|
|
|
|
+"for(int i=2; i<=10; i++)\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"vec2 marchPosition = v_texCoords + i*texelSize*direction;\n"
|
|
|
|
|
+"vec3 fragPosMarch = texture(u_gPosition, marchPosition).xyz;\n"
|
|
|
|
|
+"vec3 hVector = normalize(fragPosMarch-fragPos); \n"
|
|
|
|
|
+"float rangeCheck = 1 - saturate(length(fragPosMarch-fragPos) / RAD-1);\n"
|
|
|
|
|
+"if(hVector.z > highestZ && length(fragPosMarch-fragPos) < RAD)\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"highestZ = hVector.z;\n"
|
|
|
|
|
+"foundPos = fragPosMarch;\n"
|
|
|
|
|
+"}\n"
|
|
|
|
|
+"}\n"
|
|
|
|
|
+"vec3 horizonVector = (foundPos - fragPos);\n"
|
|
|
|
|
+"float horizonAngle = atan(horizonVector.z/length(horizonVector.xy));\n"
|
|
|
|
|
+"float sinHorizonAngle = sin(horizonAngle); \n"
|
|
|
|
|
+"vec2 rez = vec2(saturate((sinHorizonAngle - sinTangentAngle))/2, projectedLen);\n"
|
|
|
|
|
+"return rez;\n"
|
|
|
|
|
+"}\n"
|
|
|
|
|
+"void main()\n"
|
|
|
|
|
+"{\n"
|
|
|
|
|
+"vec2 screenSize = textureSize(u_gPosition, 0).xy/2.f; \n"
|
|
|
|
|
+"vec2 noiseScale = vec2(screenSize.x/4.0, screenSize.y/4.0);\n"
|
|
|
|
|
+"vec2 noisePos = v_texCoords * noiseScale;\n"
|
|
|
|
|
+"vec3 fragPos = texture(u_gPosition, v_texCoords).xyz; \n"
|
|
|
|
|
+"if(fragPos.z == -INFINITY){fragColor = 1; return;}\n"
|
|
|
|
|
+"vec3 normal = normalize( vec3( \n"
|
|
|
|
|
+"transpose(inverse(mat3(u_view))) * \n"
|
|
|
|
|
+"fromuShortToFloat(texture(u_gNormal, v_texCoords).xyz)\n"
|
|
|
|
|
+"));\n"
|
|
|
|
|
+"vec2 randomVec = vec2(0,1);\n"
|
|
|
|
|
+"vec2 rez = vec2(0,0);\n"
|
|
|
|
|
+"vec3 viewVector = normalize(fragPos);\n"
|
|
|
|
|
+"rez += computeAO(normal, vec2(randomVec), screenSize, fragPos);\n"
|
|
|
|
|
+"rez += computeAO(normal, -vec2(randomVec), screenSize, fragPos);\n"
|
|
|
|
|
+"rez += computeAO(normal, vec2(-randomVec.y,randomVec.x), screenSize, fragPos);\n"
|
|
|
|
|
+"rez += computeAO(normal, vec2(randomVec.y, -randomVec.x), screenSize, fragPos);\n"
|
|
|
|
|
+"rez.x /= rez.y;\n"
|
|
|
|
|
+"fragColor = 1.f - rez.x;\n"
|
|
|
"}\n"},
|
|
"}\n"},
|
|
|
|
|
|
|
|
std::pair<std::string, const char*>{"zPrePass.vert", "#version 430\n"
|
|
std::pair<std::string, const char*>{"zPrePass.vert", "#version 430\n"
|
|
@@ -32984,7 +33078,7 @@ namespace gl3d
|
|
|
"vec3 kS = F; \n"
|
|
"vec3 kS = F; \n"
|
|
|
"vec3 kD = vec3(1.0) - kS; \n"
|
|
"vec3 kD = vec3(1.0) - kS; \n"
|
|
|
"kD *= 1.0 - metallic; \n"
|
|
"kD *= 1.0 - metallic; \n"
|
|
|
-"vec3 diffuse = fDiffuse(color.rgb);\n"
|
|
|
|
|
|
|
+"vec3 diffuse = fDiffuseOrenNayar2(color.rgb, roughness, lightDirection, viewDir, normal);\n"
|
|
|
"float NdotL = max(dot(normal, lightDirection), 0.0); \n"
|
|
"float NdotL = max(dot(normal, lightDirection), 0.0); \n"
|
|
|
"return (kD * diffuse + specular) * radiance * NdotL;\n"
|
|
"return (kD * diffuse + specular) * radiance * NdotL;\n"
|
|
|
"}\n"
|
|
"}\n"
|
|
@@ -35919,8 +36013,10 @@ namespace gl3d
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
- void Renderer3D::init(int x, int y, GLuint frameBuffer, const char *BRDFIntegrationMapFileLocation)
|
|
|
|
|
|
|
+ void Renderer3D::init(int x, int y, const char *BRDFIntegrationMapFileLocation, GLuint frameBuffer)
|
|
|
{
|
|
{
|
|
|
|
|
+ this->frameBuffer = frameBuffer;
|
|
|
|
|
+
|
|
|
internal.w = x; internal.h = y;
|
|
internal.w = x; internal.h = y;
|
|
|
internal.adaptiveW = x;
|
|
internal.adaptiveW = x;
|
|
|
internal.adaptiveH = y;
|
|
internal.adaptiveH = y;
|
|
@@ -35954,6 +36050,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
internal.gBuffer.create(x, y, errorReporter, frameBuffer);
|
|
internal.gBuffer.create(x, y, errorReporter, frameBuffer);
|
|
|
internal.ssao.create(x, y, errorReporter, fileOpener, frameBuffer);
|
|
internal.ssao.create(x, y, errorReporter, fileOpener, frameBuffer);
|
|
|
|
|
+ internal.hbao.create(errorReporter, fileOpener, frameBuffer);
|
|
|
postProcess.create(x, y, errorReporter, fileOpener, frameBuffer);
|
|
postProcess.create(x, y, errorReporter, fileOpener, frameBuffer);
|
|
|
directionalShadows.create(frameBuffer);
|
|
directionalShadows.create(frameBuffer);
|
|
|
spotShadows.create(frameBuffer);
|
|
spotShadows.create(frameBuffer);
|
|
@@ -35994,7 +36091,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Material Renderer3D::createMaterial(GLuint frameBuffer, glm::vec4 kd,
|
|
|
|
|
|
|
+ Material Renderer3D::createMaterial(glm::vec4 kd,
|
|
|
float roughness, float metallic, float ao, std::string name,
|
|
float roughness, float metallic, float ao, std::string name,
|
|
|
gl3d::Texture albedoTexture, gl3d::Texture normalTexture, gl3d::Texture roughnessTexture, gl3d::Texture metallicTexture,
|
|
gl3d::Texture albedoTexture, gl3d::Texture normalTexture, gl3d::Texture roughnessTexture, gl3d::Texture metallicTexture,
|
|
|
gl3d::Texture occlusionTexture, gl3d::Texture emmisiveTexture)
|
|
gl3d::Texture occlusionTexture, gl3d::Texture emmisiveTexture)
|
|
@@ -36015,8 +36112,7 @@ namespace gl3d
|
|
|
textureData.emissiveTexture = emmisiveTexture;
|
|
textureData.emissiveTexture = emmisiveTexture;
|
|
|
|
|
|
|
|
|
|
|
|
|
- textureData.pbrTexture = createPBRTexture(roughnessTexture, metallicTexture, occlusionTexture,
|
|
|
|
|
- frameBuffer);
|
|
|
|
|
|
|
+ textureData.pbrTexture = createPBRTexture(roughnessTexture, metallicTexture, occlusionTexture);
|
|
|
|
|
|
|
|
|
|
|
|
|
internal.materialIndexes.push_back(id);
|
|
internal.materialIndexes.push_back(id);
|
|
@@ -36030,7 +36126,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Material Renderer3D::createMaterial(Material m, GLuint frameBuffer)
|
|
|
|
|
|
|
+ Material Renderer3D::createMaterial(Material m)
|
|
|
{
|
|
{
|
|
|
auto newM = createMaterial(frameBuffer);
|
|
auto newM = createMaterial(frameBuffer);
|
|
|
copyMaterialData(newM, m);
|
|
copyMaterialData(newM, m);
|
|
@@ -36047,7 +36143,7 @@ namespace gl3d
|
|
|
gl3d::Material createMaterialFromLoadedData(gl3d::Renderer3D &renderer,
|
|
gl3d::Material createMaterialFromLoadedData(gl3d::Renderer3D &renderer,
|
|
|
objl::Material &mat, const std::string &path, GLuint frameBuffer)
|
|
objl::Material &mat, const std::string &path, GLuint frameBuffer)
|
|
|
{
|
|
{
|
|
|
- auto m = renderer.createMaterial(frameBuffer, mat.Kd, mat.roughness,
|
|
|
|
|
|
|
+ auto m = renderer.createMaterial(mat.Kd, mat.roughness,
|
|
|
mat.metallic, mat.ao, mat.name);
|
|
mat.metallic, mat.ao, mat.name);
|
|
|
|
|
|
|
|
stbi_set_flip_vertically_on_load(true);
|
|
stbi_set_flip_vertically_on_load(true);
|
|
@@ -36372,7 +36468,7 @@ namespace gl3d
|
|
|
return m;
|
|
return m;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- std::vector<Material> Renderer3D::loadMaterial(std::string file, GLuint frameBuffer)
|
|
|
|
|
|
|
+ std::vector<Material> Renderer3D::loadMaterial(std::string file)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
objl::Loader loader;
|
|
objl::Loader loader;
|
|
@@ -36686,7 +36782,7 @@ namespace gl3d
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
PBRTexture Renderer3D::createPBRTexture(Texture& roughness, Texture& metallic,
|
|
PBRTexture Renderer3D::createPBRTexture(Texture& roughness, Texture& metallic,
|
|
|
- Texture& ambientOcclusion, GLuint frameBuffer)
|
|
|
|
|
|
|
+ Texture& ambientOcclusion)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
PBRTexture ret = {};
|
|
PBRTexture ret = {};
|
|
@@ -36708,7 +36804,7 @@ namespace gl3d
|
|
|
t.RMA_loadedTextures = 0;
|
|
t.RMA_loadedTextures = 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Model Renderer3D::loadModel(std::string path, GLuint frameBuffer, float scale)
|
|
|
|
|
|
|
+ Model Renderer3D::loadModel(std::string path, float scale)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
gl3d::LoadedModelData model(path.c_str(), errorReporter, fileOpener, scale);
|
|
gl3d::LoadedModelData model(path.c_str(), errorReporter, fileOpener, scale);
|
|
@@ -36800,7 +36896,7 @@ namespace gl3d
|
|
|
}else
|
|
}else
|
|
|
{
|
|
{
|
|
|
//if no material loaded for this object create a new default one
|
|
//if no material loaded for this object create a new default one
|
|
|
- gm.material = createMaterial(frameBuffer, glm::vec4{ 0.8f,0.8f,0.8f, 1.0f }, 0.5f, 0.f, 1.f, "default material");
|
|
|
|
|
|
|
+ gm.material = createMaterial(glm::vec4{ 0.8f,0.8f,0.8f, 1.0f }, 0.5f, 0.f, 1.f, "default material");
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
gm.ownMaterial = true;
|
|
gm.ownMaterial = true;
|
|
@@ -37551,7 +37647,7 @@ namespace gl3d
|
|
|
return e;
|
|
return e;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- Entity Renderer3D::duplicateEntity(Entity& e, GLuint frameBuffer)
|
|
|
|
|
|
|
+ Entity Renderer3D::duplicateEntity(Entity& e)
|
|
|
{
|
|
{
|
|
|
int oldIndex = internal.getEntityIndex(e);
|
|
int oldIndex = internal.getEntityIndex(e);
|
|
|
|
|
|
|
@@ -37792,7 +37888,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void Renderer3D::setEntityMeshMaterialValues(Entity& e, int meshIndex, MaterialValues mat, GLuint frameBuffer)
|
|
|
|
|
|
|
+ void Renderer3D::setEntityMeshMaterialValues(Entity& e, int meshIndex, MaterialValues mat)
|
|
|
{
|
|
{
|
|
|
auto i = internal.getEntityIndex(e);
|
|
auto i = internal.getEntityIndex(e);
|
|
|
if (i < 0) { return ; } //warn or sthing
|
|
if (i < 0) { return ; } //warn or sthing
|
|
@@ -37813,7 +37909,7 @@ namespace gl3d
|
|
|
}else
|
|
}else
|
|
|
if (mat != data)
|
|
if (mat != data)
|
|
|
{
|
|
{
|
|
|
- Material newMat = this->createMaterial(frameBuffer, mat.kd, mat.roughness,
|
|
|
|
|
|
|
+ Material newMat = this->createMaterial(mat.kd, mat.roughness,
|
|
|
mat.metallic, mat.ao, name);
|
|
mat.metallic, mat.ao, name);
|
|
|
int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
|
|
int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
|
|
|
|
|
|
|
@@ -37861,7 +37957,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void Renderer3D::setEntityMeshMaterialName(Entity& e, int meshIndex, const std::string& name, GLuint frameBuffer)
|
|
|
|
|
|
|
+ void Renderer3D::setEntityMeshMaterialName(Entity& e, int meshIndex, const std::string& name)
|
|
|
{
|
|
{
|
|
|
auto i = internal.getEntityIndex(e);
|
|
auto i = internal.getEntityIndex(e);
|
|
|
if (i < 0) { return; } //warn or sthing
|
|
if (i < 0) { return; } //warn or sthing
|
|
@@ -37883,7 +37979,7 @@ namespace gl3d
|
|
|
else
|
|
else
|
|
|
if (name != oldName) //copy to new material
|
|
if (name != oldName) //copy to new material
|
|
|
{
|
|
{
|
|
|
- Material newMat = this->createMaterial(frameBuffer, data.kd, data.roughness,
|
|
|
|
|
|
|
+ Material newMat = this->createMaterial(data.kd, data.roughness,
|
|
|
data.metallic, data.ao, name);
|
|
data.metallic, data.ao, name);
|
|
|
int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
|
|
int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
|
|
|
internal.materialTexturesData[newMatIndex] = textures;
|
|
internal.materialTexturesData[newMatIndex] = textures;
|
|
@@ -37956,7 +38052,7 @@ namespace gl3d
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- void Renderer3D::setEntityMeshMaterialTextures(Entity& e, int meshIndex, TextureDataForMaterial texture, GLuint frameBuffer)
|
|
|
|
|
|
|
+ void Renderer3D::setEntityMeshMaterialTextures(Entity& e, int meshIndex, TextureDataForMaterial texture)
|
|
|
{
|
|
{
|
|
|
auto i = internal.getEntityIndex(e);
|
|
auto i = internal.getEntityIndex(e);
|
|
|
if (i < 0) { return; } //warn or sthing
|
|
if (i < 0) { return; } //warn or sthing
|
|
@@ -37978,7 +38074,7 @@ namespace gl3d
|
|
|
else
|
|
else
|
|
|
if (texture != oldTextures) //copy to new material
|
|
if (texture != oldTextures) //copy to new material
|
|
|
{
|
|
{
|
|
|
- Material newMat = this->createMaterial(frameBuffer, data.kd, data.roughness,
|
|
|
|
|
|
|
+ Material newMat = this->createMaterial(data.kd, data.roughness,
|
|
|
data.metallic, data.ao, oldName);
|
|
data.metallic, data.ao, oldName);
|
|
|
int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
|
|
int newMatIndex = internal.getMaterialIndex(newMat); //this should not fail
|
|
|
internal.materialTexturesData[newMatIndex] = texture; //new textures
|
|
internal.materialTexturesData[newMatIndex] = texture; //new textures
|
|
@@ -38882,10 +38978,10 @@ namespace gl3d
|
|
|
};
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
|
- void Renderer3D::render(float deltaTime, GLuint frameBuffer)
|
|
|
|
|
|
|
+ void Renderer3D::render(float deltaTime)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- if (internal.w == 0 || internal.h == 0)
|
|
|
|
|
|
|
+ if (internal.w <= 0 || internal.h <= 0)
|
|
|
{
|
|
{
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
@@ -40031,9 +40127,16 @@ namespace gl3d
|
|
|
|
|
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
|
|
|
|
|
|
-
|
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, internal.gBuffer.gBuffer);
|
|
|
|
|
- glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
|
|
+ #pragma region clear gbuffer
|
|
|
|
|
+ {
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, internal.gBuffer.gBuffer);
|
|
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
|
|
|
+
|
|
|
|
|
+ float clearPositionColor[4] = {0,0,-INFINITY, 0};
|
|
|
|
|
+ glClearBufferfv(GL_COLOR, internal.gBuffer.positionViewSpace, clearPositionColor);
|
|
|
|
|
+ }
|
|
|
|
|
+ #pragma endregion
|
|
|
|
|
+
|
|
|
glViewport(0, 0, internal.adaptiveW, internal.adaptiveH);
|
|
glViewport(0, 0, internal.adaptiveW, internal.adaptiveH);
|
|
|
|
|
|
|
|
|
|
|
|
@@ -40236,7 +40339,7 @@ namespace gl3d
|
|
|
for (auto& i : entity.models)
|
|
for (auto& i : entity.models)
|
|
|
{
|
|
{
|
|
|
|
|
|
|
|
- if (frustumCulling && i.culledThisFrame)
|
|
|
|
|
|
|
+ if (frustumCulling && i.culledThisFrame) //todo data oriented design, move not culled objects to a new buffer
|
|
|
{
|
|
{
|
|
|
continue;
|
|
continue;
|
|
|
}
|
|
}
|
|
@@ -40508,54 +40611,105 @@ namespace gl3d
|
|
|
|
|
|
|
|
if (internal.lightShader.useSSAO)
|
|
if (internal.lightShader.useSSAO)
|
|
|
{
|
|
{
|
|
|
- glViewport(0, 0, internal.adaptiveW / 2, internal.adaptiveH / 2);
|
|
|
|
|
|
|
|
|
|
- glUseProgram(internal.ssao.shader.id);
|
|
|
|
|
|
|
+ if (1)
|
|
|
|
|
+ {
|
|
|
|
|
+ //ssao
|
|
|
|
|
|
|
|
- //todo lazyness
|
|
|
|
|
- glBindBuffer(GL_UNIFORM_BUFFER, internal.ssao.ssaoUniformBlockBuffer);
|
|
|
|
|
- glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(InternalStruct::SSAO::SsaoShaderUniformBlockData),
|
|
|
|
|
- &internal.ssao.ssaoShaderUniformBlockData);
|
|
|
|
|
|
|
+ glViewport(0, 0, internal.adaptiveW / 2, internal.adaptiveH / 2);
|
|
|
|
|
|
|
|
- glUniformMatrix4fv(internal.ssao.u_projection, 1, GL_FALSE,
|
|
|
|
|
- &(camera.getProjectionMatrix())[0][0]);
|
|
|
|
|
|
|
+ glUseProgram(internal.ssao.shader.id);
|
|
|
|
|
|
|
|
- glUniformMatrix4fv(internal.ssao.u_view, 1, GL_FALSE,
|
|
|
|
|
- &(camera.getWorldToViewMatrix())[0][0]);
|
|
|
|
|
|
|
+ //todo lazyness
|
|
|
|
|
+ glBindBuffer(GL_UNIFORM_BUFFER, internal.ssao.ssaoUniformBlockBuffer);
|
|
|
|
|
+ glBufferSubData(GL_UNIFORM_BUFFER, 0, sizeof(InternalStruct::SSAO::SsaoShaderUniformBlockData),
|
|
|
|
|
+ &internal.ssao.ssaoShaderUniformBlockData);
|
|
|
|
|
|
|
|
- glUniform3fv(internal.ssao.u_samples, 64, &(internal.ssao.ssaoKernel[0][0]));
|
|
|
|
|
|
|
+ glUniformMatrix4fv(internal.ssao.u_projection, 1, GL_FALSE,
|
|
|
|
|
+ &(camera.getProjectionMatrix())[0][0]);
|
|
|
|
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, internal.ssao.ssaoFBO);
|
|
|
|
|
- glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
+ glUniformMatrix4fv(internal.ssao.u_view, 1, GL_FALSE,
|
|
|
|
|
+ &(camera.getWorldToViewMatrix())[0][0]);
|
|
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, internal.gBuffer.buffers[internal.gBuffer.positionViewSpace]);
|
|
|
|
|
- glUniform1i(internal.ssao.u_gPosition, 0);
|
|
|
|
|
|
|
+ glUniform3fv(internal.ssao.u_samples, 64, &(internal.ssao.ssaoKernel[0][0]));
|
|
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE1);
|
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, internal.gBuffer.buffers[internal.gBuffer.normal]);
|
|
|
|
|
- glUniform1i(internal.ssao.u_gNormal, 1);
|
|
|
|
|
|
|
|
|
|
- glActiveTexture(GL_TEXTURE2);
|
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, internal.ssao.noiseTexture);
|
|
|
|
|
- glUniform1i(internal.ssao.u_texNoise, 2);
|
|
|
|
|
|
|
+ glUniform1f(internal.ssao.u_aspectRatio, camera.aspectRatio);
|
|
|
|
|
+ glUniform1f(internal.ssao.u_tanHalfFOV, std::tan(camera.fovRadians/2.f));
|
|
|
|
|
+
|
|
|
|
|
+ glUniform1f(internal.ssao.u_farPlane, camera.farPlane);
|
|
|
|
|
+ glUniform1f(internal.ssao.u_closePlane, camera.closePlane);
|
|
|
|
|
+
|
|
|
|
|
|
|
|
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, internal.ssao.ssaoFBO);
|
|
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.gBuffer.buffers[internal.gBuffer.positionViewSpace]);
|
|
|
|
|
+ glUniform1i(internal.ssao.u_gPosition, 0);
|
|
|
|
|
|
|
|
- #pragma region ssao "blur" (more like average blur)
|
|
|
|
|
- glViewport(0, 0, internal.adaptiveW / 4, internal.adaptiveH / 4);
|
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE1);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.gBuffer.buffers[internal.gBuffer.normal]);
|
|
|
|
|
+ glUniform1i(internal.ssao.u_gNormal, 1);
|
|
|
|
|
|
|
|
- glBindFramebuffer(GL_FRAMEBUFFER, internal.ssao.blurBuffer);
|
|
|
|
|
- internal.ssao.blurShader.bind();
|
|
|
|
|
- glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
- glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
- glBindTexture(GL_TEXTURE_2D, internal.ssao.ssaoColorBuffer);
|
|
|
|
|
- glUniform1i(internal.ssao.u_ssaoInput, 0);
|
|
|
|
|
- glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE2);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.ssao.noiseTexture);
|
|
|
|
|
+ glUniform1i(internal.ssao.u_texNoise, 2);
|
|
|
|
|
|
|
|
- glViewport(0, 0, internal.adaptiveW, internal.adaptiveH);
|
|
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE3);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.gBuffer.depthBuffer);
|
|
|
|
|
+ glUniform1i(internal.ssao.u_depthBuffer, 3);
|
|
|
|
|
+
|
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+ else
|
|
|
|
|
+ {
|
|
|
|
|
+ //hbao
|
|
|
|
|
+ glViewport(0, 0, internal.adaptiveW / 2, internal.adaptiveH / 2);
|
|
|
|
|
+ glUseProgram(internal.hbao.shader.id);
|
|
|
|
|
+
|
|
|
|
|
+ glUniformMatrix4fv(internal.hbao.u_projection, 1, GL_FALSE,
|
|
|
|
|
+ &(camera.getProjectionMatrix())[0][0]);
|
|
|
|
|
+ glUniformMatrix4fv(internal.hbao.u_view, 1, GL_FALSE,
|
|
|
|
|
+ &(camera.getWorldToViewMatrix())[0][0]);
|
|
|
|
|
+
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, internal.ssao.ssaoFBO);
|
|
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
+
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.gBuffer.buffers[internal.gBuffer.positionViewSpace]);
|
|
|
|
|
+ glUniform1i(internal.hbao.u_gPosition, 0);
|
|
|
|
|
+
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE1);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.gBuffer.buffers[internal.gBuffer.normal]);
|
|
|
|
|
+ glUniform1i(internal.hbao.u_gNormal, 1);
|
|
|
|
|
+
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE2);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.ssao.noiseTexture);
|
|
|
|
|
+ glUniform1i(internal.hbao.u_texNoise, 2);
|
|
|
|
|
+
|
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ #pragma region ssao/hbao "blur" (more like average blur)
|
|
|
|
|
+ glViewport(0, 0, internal.adaptiveW / 4, internal.adaptiveH / 4);
|
|
|
|
|
+
|
|
|
|
|
+ glBindFramebuffer(GL_FRAMEBUFFER, internal.ssao.blurBuffer);
|
|
|
|
|
+ internal.ssao.blurShader.bind();
|
|
|
|
|
+ glClear(GL_COLOR_BUFFER_BIT);
|
|
|
|
|
+ glActiveTexture(GL_TEXTURE0);
|
|
|
|
|
+ glBindTexture(GL_TEXTURE_2D, internal.ssao.ssaoColorBuffer);
|
|
|
|
|
+ glUniform1i(internal.ssao.u_ssaoInput, 0);
|
|
|
|
|
+ glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
+ glViewport(0, 0, internal.adaptiveW, internal.adaptiveH);
|
|
|
|
|
+
|
|
|
}
|
|
}
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
|
|
|
|
|
@@ -40983,7 +41137,7 @@ namespace gl3d
|
|
|
//gbuffer
|
|
//gbuffer
|
|
|
internal.gBuffer.resize(internal.adaptiveW, internal.adaptiveH);
|
|
internal.gBuffer.resize(internal.adaptiveW, internal.adaptiveH);
|
|
|
|
|
|
|
|
- //ssao
|
|
|
|
|
|
|
+ //ssao and hbao
|
|
|
internal.ssao.resize(internal.adaptiveW, internal.adaptiveH);
|
|
internal.ssao.resize(internal.adaptiveW, internal.adaptiveH);
|
|
|
|
|
|
|
|
//bloom buffer and color buffer
|
|
//bloom buffer and color buffer
|
|
@@ -41024,7 +41178,7 @@ namespace gl3d
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SkyBox Renderer3D::loadSkyBox(const char *names[6], GLuint frameBuffer)
|
|
|
|
|
|
|
+ SkyBox Renderer3D::loadSkyBox(const char *names[6])
|
|
|
{
|
|
{
|
|
|
SkyBox skyBox = {};
|
|
SkyBox skyBox = {};
|
|
|
internal.skyBoxLoaderAndDrawer.loadTexture(names, skyBox, errorReporter, fileOpener, frameBuffer);
|
|
internal.skyBoxLoaderAndDrawer.loadTexture(names, skyBox, errorReporter, fileOpener, frameBuffer);
|
|
@@ -41038,7 +41192,7 @@ namespace gl3d
|
|
|
return skyBox;
|
|
return skyBox;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SkyBox Renderer3D::loadHDRSkyBox(const char *name, GLuint frameBuffer)
|
|
|
|
|
|
|
+ SkyBox Renderer3D::loadHDRSkyBox(const char *name)
|
|
|
{
|
|
{
|
|
|
SkyBox skyBox = {};
|
|
SkyBox skyBox = {};
|
|
|
internal.skyBoxLoaderAndDrawer.loadHDRtexture(name, errorReporter, fileOpener, skyBox, frameBuffer);
|
|
internal.skyBoxLoaderAndDrawer.loadHDRtexture(name, errorReporter, fileOpener, skyBox, frameBuffer);
|
|
@@ -41050,7 +41204,7 @@ namespace gl3d
|
|
|
skyBox.clearTextures();
|
|
skyBox.clearTextures();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- SkyBox Renderer3D::atmosfericScattering(glm::vec3 sun, glm::vec3 color1, glm::vec3 color2, float g, GLuint frameBuffer)
|
|
|
|
|
|
|
+ SkyBox Renderer3D::atmosfericScattering(glm::vec3 sun, glm::vec3 color1, glm::vec3 color2, float g)
|
|
|
{
|
|
{
|
|
|
SkyBox skyBox = {};
|
|
SkyBox skyBox = {};
|
|
|
internal.skyBoxLoaderAndDrawer.atmosphericScattering(sun, color1, color2, g, skyBox, frameBuffer);
|
|
internal.skyBoxLoaderAndDrawer.atmosphericScattering(sun, color1, color2, g, skyBox, frameBuffer);
|
|
@@ -41132,7 +41286,13 @@ namespace gl3d
|
|
|
u_gNormal = getUniform(shader.id, "u_gNormal", errorReporter);
|
|
u_gNormal = getUniform(shader.id, "u_gNormal", errorReporter);
|
|
|
u_texNoise = getUniform(shader.id, "u_texNoise", errorReporter);
|
|
u_texNoise = getUniform(shader.id, "u_texNoise", errorReporter);
|
|
|
u_samples = getUniform(shader.id, "samples[0]", errorReporter);
|
|
u_samples = getUniform(shader.id, "samples[0]", errorReporter);
|
|
|
-
|
|
|
|
|
|
|
+ u_depthBuffer = getUniform(shader.id, "u_depthBuffer", errorReporter);
|
|
|
|
|
+ u_aspectRatio = getUniform(shader.id, "u_aspectRatio", errorReporter);
|
|
|
|
|
+ u_tanHalfFOV = getUniform(shader.id, "u_tanHalfFOV", errorReporter);
|
|
|
|
|
+ u_farPlane = getUniform(shader.id, "u_farPlane", errorReporter);
|
|
|
|
|
+ u_closePlane = getUniform(shader.id, "u_closePlane", errorReporter);
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
|
|
|
|
|
glGenBuffers(1, &ssaoUniformBlockBuffer);
|
|
glGenBuffers(1, &ssaoUniformBlockBuffer);
|
|
|
glBindBuffer(GL_UNIFORM_BUFFER, ssaoUniformBlockBuffer);
|
|
glBindBuffer(GL_UNIFORM_BUFFER, ssaoUniformBlockBuffer);
|
|
@@ -41883,6 +42043,20 @@ namespace gl3d
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ void Renderer3D::InternalStruct::HBAO::create(ErrorReporter &errorReporter, FileOpener &fileOpener, GLuint frameBuffer)
|
|
|
|
|
+ {
|
|
|
|
|
+
|
|
|
|
|
+ shader.loadShaderProgramFromFile("shaders/drawQuads.vert", "shaders/hbao/hbao.frag", errorReporter, fileOpener);
|
|
|
|
|
+
|
|
|
|
|
+ u_projection = getUniform(shader.id, "u_projection", errorReporter);
|
|
|
|
|
+ u_view = getUniform(shader.id, "u_view", errorReporter);
|
|
|
|
|
+ u_gPosition = getUniform(shader.id, "u_gPosition", errorReporter);
|
|
|
|
|
+ u_gNormal = getUniform(shader.id, "u_gNormal", errorReporter);
|
|
|
|
|
+ u_texNoise = getUniform(shader.id, "u_texNoise", errorReporter);
|
|
|
|
|
+
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+
|
|
|
};
|
|
};
|
|
|
#pragma endregion
|
|
#pragma endregion
|
|
|
|
|
|