Adding nanosuit for testing purposes, struggling on making that god damned Gbuffer work

This commit is contained in:
Hurlu 2019-06-03 17:45:39 +09:00
parent ea937db226
commit 32071d672e
48 changed files with 52511 additions and 702 deletions

View File

@ -95,7 +95,7 @@
<GenerateDebugInformation>true</GenerateDebugInformation>
<SubSystem>Console</SubSystem>
<AdditionalLibraryDirectories>C:\Graphics\Tools\SOIL\lib;C:\Graphics\Tools\Assimp\lib\x86;C:\Graphics\Tools\glfw\lib\x86;C:\Graphics\Tools\glew\lib;%(AdditionalLibraryDirectories)</AdditionalLibraryDirectories>
<AdditionalDependencies>assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
<AdditionalDependencies>assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;FreeImage.lib;%(AdditionalDependencies)</AdditionalDependencies>
</Link>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
@ -147,7 +147,6 @@
</ItemDefinitionGroup>
<ItemGroup>
<ClCompile Include="Dataset.cpp" />
<ClCompile Include="fboManager.cpp" />
<ClCompile Include="imgui\imgui.cpp" />
<ClCompile Include="imgui\imgui_demo.cpp" />
<ClCompile Include="imgui\imgui_draw.cpp" />
@ -162,13 +161,10 @@
<ClCompile Include="Skybox.cpp" />
<ClCompile Include="Source.cpp" />
<ClCompile Include="Texture.cpp" />
<ClCompile Include="textureManager.cpp" />
<ClCompile Include="TextureViewer.cpp" />
<ClCompile Include="Viewer.cpp" />
</ItemGroup>
<ItemGroup>
<ClInclude Include="Dataset.h" />
<ClInclude Include="fboManager.h" />
<ClInclude Include="imgui\imconfig.h" />
<ClInclude Include="imgui\imgui.h" />
<ClInclude Include="imgui\imgui_impl_glfw.h" />
@ -188,8 +184,6 @@
<ClInclude Include="Shader.h" />
<ClInclude Include="Skybox.h" />
<ClInclude Include="Texture.h" />
<ClInclude Include="textureManager.h" />
<ClInclude Include="TextureViewer.h" />
<ClInclude Include="Viewer.h" />
</ItemGroup>
<ItemGroup>
@ -201,8 +195,6 @@
<None Include="fog.frag" />
<None Include="fog.vert" />
<None Include="base_light.vert" />
<None Include="GBufferVisual.frag" />
<None Include="GBufferVisual.vert" />
<None Include="light_pov.frag" />
<None Include="light_pov.vert" />
<None Include="nmap.frag" />

View File

@ -22,9 +22,6 @@
<Filter Include="Models">
<UniqueIdentifier>{af32f844-b061-4424-a685-e3f537232cf8}</UniqueIdentifier>
</Filter>
<Filter Include="MankyuCode">
<UniqueIdentifier>{b0c228ca-8e29-48df-a9f6-59fb58accad5}</UniqueIdentifier>
</Filter>
<Filter Include="Shaders\PPShaders">
<UniqueIdentifier>{be4b14ab-faab-4412-8a5b-ce9c1510772f}</UniqueIdentifier>
</Filter>
@ -75,15 +72,6 @@
<ClCompile Include="Skybox.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="fboManager.cpp">
<Filter>MankyuCode</Filter>
</ClCompile>
<ClCompile Include="textureManager.cpp">
<Filter>MankyuCode</Filter>
</ClCompile>
<ClCompile Include="TextureViewer.cpp">
<Filter>MankyuCode</Filter>
</ClCompile>
<ClCompile Include="Multipass.cpp">
<Filter>Source Files</Filter>
</ClCompile>
@ -149,15 +137,6 @@
<ClInclude Include="Skybox.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="fboManager.h">
<Filter>MankyuCode</Filter>
</ClInclude>
<ClInclude Include="textureManager.h">
<Filter>MankyuCode</Filter>
</ClInclude>
<ClInclude Include="TextureViewer.h">
<Filter>MankyuCode</Filter>
</ClInclude>
<ClInclude Include="Multipass.h">
<Filter>Header Files</Filter>
</ClInclude>
@ -230,12 +209,6 @@
<None Include="textureViewer.vert">
<Filter>Shaders\PPShaders</Filter>
</None>
<None Include="GBufferVisual.vert">
<Filter>Shaders\PPShaders</Filter>
</None>
<None Include="GBufferVisual.frag">
<Filter>Shaders\PPShaders</Filter>
</None>
<None Include="DSLightPass.frag">
<Filter>Shaders\PPShaders</Filter>
</None>

View File

@ -7,17 +7,16 @@ in vec2 TexCoords;
in vec3 FragPos;
in vec3 Normal;
//uniform sampler2D texture_diffuse1;
uniform sampler2D[32] tex;
void main()
{
// store the fragment position vector in the first gbuffer texture
gPosition = FragPos;
gPosition = FragPos;
// also store the per-fragment normals into the gbuffer
gNormal = normalize(Normal);
// and the diffuse per-fragment color
gAlbedoSpec.rgb = vec3(1, 1, 1);
//gAlbedoSpec.rgb = texture(texture_diffuse1, TexCoords).rgb;
// and the diffuse per-fragment color
gAlbedoSpec.rgb = texture(tex[0], TexCoords).rgb;
// store specular intensity in gAlbedoSpec's alpha component
//gAlbedoSpec.a = texture(texture_specular1, TexCoords).r;
gAlbedoSpec.a = 1;

View File

@ -8,12 +8,14 @@ out vec2 TexCoords;
out vec3 FragPos;
out vec3 Normal;
uniform mat3 NormalMatrix;
uniform mat4 ModelMatrix;
uniform mat4 mvp;
void main(void)
{
Normal = v_normal;
Normal = v_normal * NormalMatrix;
TexCoords = v_texmap;
gl_Position = mvp * vec4(coord3d, 1.0f);
FragPos = gl_Position.xyz;
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
gl_Position = mvp * vec4(coord3d, 1.0f);
}

View File

@ -304,8 +304,8 @@ void Mesh::MeshEntry::textureBinding(Shader * shd)
glBindTexture(GL_TEXTURE_2D, textures[i].tex_ref);
shd->addUniform("tex[" + std::to_string(i) + "]", (int)i);
}
if (textures.size() > 0)
shd->addUniform("TexCount", (int)textures.size());
//if (textures.size() > 0)
//shd->addUniform("TexCount", (int)textures.size());
}
void Mesh::MeshEntry::textureUnbinding()
@ -353,9 +353,7 @@ Mesh::Mesh(const char *filename, Shader *sh)
textures.emplace(FullPath, Texture(FullPath));
}
}
}
}
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
meshEntries.push_back(new Mesh::MeshEntry(scene->mMeshes[i], scene, this));
@ -414,7 +412,7 @@ void Mesh::textureBinding(Shader *shd)
{
glActiveTexture(GL_TEXTURE0 + i);
glBindTexture(GL_TEXTURE_2D, it->second.tex_ref);
shd->applyTextureMaterial(it->second);
//shd->applyTextureMaterial(it->second);
if (it->second.isNmap)
{
shd->addUniform("nmap", (int)i);
@ -424,8 +422,8 @@ void Mesh::textureBinding(Shader *shd)
shd->addUniform("tex[" + std::to_string(i - nmap_counter) + "]", (int)i);
i++;
}
if (textures.size() > 0)
shd->addUniform("TexCount", (int)textures.size() - nmap_counter);
/*if (textures.size() > 0)
shd->addUniform("TexCount", (int)textures.size() - nmap_counter);*/
}
void Mesh::draw(SceneContext &ctx) {

Binary file not shown.

After

Width:  |  Height:  |  Size: 562 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 846 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 386 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 621 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 840 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 90 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 100 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 86 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 277 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 63 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 42 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 570 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 52 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 640 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 976 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 64 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 513 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 729 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 55 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.5 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 73 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.7 MiB

View File

@ -0,0 +1,79 @@
# Blender MTL File: 'nanosuit.blend'
# Material Count: 6
newmtl Arm
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump arm_showroom_ddn.png
map_Ka arm_showroom_refl.png
map_Kd arm_dif.png
map_Ks arm_showroom_spec.png
newmtl Body
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Kd body_dif.png
map_Bump body_showroom_ddn.png
map_Ka body_showroom_refl.png
map_Ks body_showroom_spec.png
newmtl Glass
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump glass_ddn.png
map_Ka glass_refl.png
map_Kd glass_dif.png
newmtl Hand
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump hand_showroom_ddn.png
map_Ka hand_showroom_refl.png
map_Kd hand_dif.png
map_Ks hand_showroom_spec.png
newmtl Helmet
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump helmet_showroom_ddn.png
map_Ka helmet_showroom_refl.png
map_Kd helmet_diff.png
map_Ks helmet_showroom_spec.png
newmtl Leg
Ns 96.078431
Ka 0.000000 0.000000 0.000000
Kd 0.640000 0.640000 0.640000
Ks 0.500000 0.500000 0.500000
Ni 1.000000
d 1.000000
illum 2
map_Bump leg_showroom_ddn.png
map_Ka leg_showroom_refl.png
map_Kd leg_dif.png
map_Ks leg_showroom_spec.png

File diff suppressed because it is too large Load Diff

View File

@ -68,14 +68,26 @@ void Multipass::enableFrameBufferTexture(const std::string tex_name)
void Multipass::drawResultToScreen(SceneContext & scnctx)
{
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glViewport(0, 0, scnctx.width, scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glViewport(0, 0, scnctx.width, scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
shader->enable();
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, _pass_textures[_current_tex]);
shader->addUniform("tex", 0);
glBindVertexArray(_quad_vao);
glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo);
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
glBindTexture(GL_TEXTURE_2D, 0);
static GLuint clearColor[4] = { 0, 0, 0, 0 };
glClearTexImage(_pass_textures[_current_tex], 0, GL_BGRA, GL_UNSIGNED_BYTE, &clearColor);
glBindTexture(GL_TEXTURE_2D, 0);
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
shader->disable();

View File

@ -1,4 +1,6 @@
#include "MyGlWindow.h"
#include "FreeImage.h"
//Getting the projection matrix
glm::mat4x4 perspective(float fovy, float aspect, float near, float far)
{
@ -129,7 +131,7 @@ void MyGlWindow::shaderSetup()
void MyGlWindow::lightSetup()
{
//Showcase lights
//_scnctx.lights.emplace("Spotlight1", Light(glm::vec3(0.8f), glm::vec4(10, 10, 10, 1)));
_scnctx.lights.emplace("Spotlight1", Light(glm::vec3(0.8f), glm::vec4(10, 10, 10, 1)));
// 24, 12, 2, glm::vec4(0, 1, 0, 1)));
//Party lights
@ -141,8 +143,7 @@ void MyGlWindow::lightSetup()
}
void MyGlWindow::multipassSetup()
{
_multipassManager.shader = shaders["GBufferVisual"];
{
_multipassManager.addTexture("position_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_FLOAT, false, _scnctx);
_multipassManager.addTexture("normal_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_UNSIGNED_BYTE, false, _scnctx);
_multipassManager.addTexture("color_buffer", GL_NEAREST, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, _scnctx);
@ -151,11 +152,7 @@ void MyGlWindow::multipassSetup()
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
_multipassManager.setDrawBuffers();
//Deferred lighting shader
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "DisplayAlbedo");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "DisplayPositions");
_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "DisplayNormals");
//Standard post-process shader
/*_multipassManager.shader->addSubroutine(GL_FRAGMENT_SHADER, "depthing");
@ -173,18 +170,35 @@ void MyGlWindow::setup()
glEnable(GL_DEPTH_BUFFER);
glEnable(GL_TEXTURE_2D);
_scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
textureSetup();
shaderSetup();
skybox.initialize("Models/Skybox/", shaders["Skybox"]);
skybox.scale = 10;
_scnctx.skybox_tex = skybox.getTexID();
shaderSetup();
lightSetup();
multipassSetup();
Dataset moddata;
moddata.checkeredFloor(100, 100, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7));
meshes.emplace("Floor", new Mesh(moddata, shaders["DSGeometryPass"]));
//Scene for GBuffer Testing
/*Mesh *nanosuit_A = new Mesh("nanosuit/nanosuit.obj", shaders["DSGeometryPass"]);
Mesh *nanosuit_B = new Mesh("nanosuit/nanosuit.obj", shaders["DSGeometryPass"]);
Mesh *nanosuit_C = new Mesh("nanosuit/nanosuit.obj", shaders["DSGeometryPass"]);
nanosuit_A->addStartScaling(glm::vec4(0.2, 0.2, 0.2, 1));
nanosuit_B->addStartScaling(glm::vec4(0.2, 0.2, 0.2, 1));
nanosuit_C->addStartScaling(glm::vec4(0.2, 0.2, 0.2, 1));
nanosuit_A->addStartTranslation(glm::vec4(-10, 0, 0, 1));
nanosuit_C->addStartTranslation(glm::vec4(10, 0, 0, 1));
meshes.emplace("Nanosuit_A", nanosuit_A);
meshes.emplace("Nanosuit_B", nanosuit_B);
meshes.emplace("Nanosuit_C", nanosuit_C);
*/
//Scene for light testing
moddata.simpleCube();
//Hardcoded seed for easy scene replication
@ -194,24 +208,25 @@ void MyGlWindow::setup()
for (int i = 0; i < 30; i++)
{
std::string cube_name = "Cube" + std::to_string(i);
meshes.emplace(cube_name, new Mesh(moddata, shaders["DSGeometryPass"]));
meshes.emplace(cube_name, new Mesh("cube/cube.obj", shaders["DSGeometryPass"]));
meshes[cube_name]->textures["cube_tex"] = Texture("./Models/cube/color_map.png");
float pos_x = std::rand() % 100 - 50;
float pos_z = std::rand() % 100 - 50;
//float pos_x = std::rand() % 100 + 50;
//float pos_z = std::rand() % 100 + 50;
meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0));
meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0));
meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, pos_z, 0));
meshes[cube_name]->addStartRotation(glm::vec4(1, 0, 0, std::rand() % 360));
meshes[cube_name]->addStartRotation(glm::vec4(0, 1, 0, std::rand() % 360));
meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360));
float light_r = (40 + std::rand() % 60) / 100.f;
float light_g = (40 + std::rand() % 60) / 100.f;
float light_b = (40 + std::rand() % 60) / 100.f;
//meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0));
//meshes[cube_name]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0));
//meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, pos_z, 0));
//meshes[cube_name]->addStartRotation(glm::vec4(1, 0, 0, std::rand() % 360));
//meshes[cube_name]->addStartRotation(glm::vec4(0, 1, 0, std::rand() % 360));
//meshes[cube_name]->addStartRotation(glm::vec4(0, 0, 1, std::rand() % 360));
//
//float light_r = (40 + std::rand() % 60) / 100.f;
//float light_g = (40 + std::rand() % 60) / 100.f;
//float light_b = (40 + std::rand() % 60) / 100.f;
_scnctx.lights.emplace("RandLight" + i,
Light(glm::vec3(light_r, light_g, light_b), glm::vec4(pos_x, 2, pos_z, 1)));
//_scnctx.lights.emplace("RandLight" + i,
// Light(glm::vec3(light_r, light_g, light_b), glm::vec4(pos_x, 2, pos_z, 1)));
}
}
@ -233,16 +248,13 @@ void MyGlWindow::draw()
glViewport(0, 0, _scnctx.width, _scnctx.height);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
_multipassManager.enableFrameBufferTexture("color_buffer");
_multipassManager.enableFrameBufferTexture("position_buffer");
for (auto it = meshes.begin(); it != meshes.end(); it++)
(*it).second->draw(_scnctx);
_multipassManager.drawResultToScreen(_scnctx);
_multipassManager.drawResultToScreen(_scnctx);
}
void MyGlWindow::resize(int w, int h)
{
m_width = w;

View File

@ -175,7 +175,7 @@ int loop(GLFWwindow *window)
ImGui_ImplGlfw_NewFrame();
ImGui::NewFrame();
if (ImGui::Begin("First Window"))
/*if (ImGui::Begin("First Window"))
{
ImGui::SetWindowPos(ImVec2(20, 20));
@ -183,7 +183,7 @@ int loop(GLFWwindow *window)
ImGui::ColorEdit3("Background", bgColor, 0);
glWin.setBgColor(bgColor);
}
ImGui::End();
ImGui::End();*/
double currentTime = glfwGetTime();
frameCount++;

View File

@ -1,135 +0,0 @@
#include "TextureViewer.h"
TextureViewer::TextureViewer()
{
this->s = new ShaderProgram();
this->fs = "default.frag";
this->vs = "default.vs";
this->depth = false;
setUpShaders();
}
TextureViewer::TextureViewer(GLuint tex, std::string vs, std::string fs) {
this->s = new ShaderProgram();
this->texture = tex;
this->fs = fs;
this->vs = vs;
this->depth = false;
setUpShaders();
}
TextureViewer::~TextureViewer()
{
delete s;
glDeleteBuffers(1, &VBO);
glDeleteBuffers(1, &VAO);
}
void TextureViewer::draw() {
//Bind VAO
glBindVertexArray(VAO);
//Bind VBO
glBindBuffer(GL_ARRAY_BUFFER, VBO);
s->use();
glUniform1i(s->uniform("depth"), this->depth);
//Bind texture
glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D, this->texture);
//Draw
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
//Unbind texture for sure
glBindTexture(GL_TEXTURE_2D, 0);
s->disable();
//Unbind VBO - just for sure
glBindBuffer(GL_ARRAY_BUFFER, 0);
//Unbind VAO
glBindVertexArray(0);
}
void TextureViewer::setDepthOnly(bool depth) {
this->depth = depth;
}
//Called only once in constructor
void TextureViewer::setUpShaders()
{
//We need only vertex and fragment shaders
s->initFromFiles(this->vs,this->fs);
s->use();
//Create uniforms and attributes (filled later)
s->addUniform("tex");
s->addUniform("depth");
//Quad verticles - omitted z coord, because it will always be 1
float pos[] = {
-1.0, 1.0,
1.0, 1.0,
-1.0, -1.0,
1.0, -1.0
};
float uv[] = {
0.0, 1.0,
1.0, 1.0,
0.0, 0.0,
1.0, 0.0
};
//Generate VAO
glGenVertexArrays(1, &VAO);
//Bind VAO
glBindVertexArray(VAO);
//Generate VBO
glGenBuffers(1, &VBO);
//Bind VBO
glBindBuffer(GL_ARRAY_BUFFER, VBO);
//Alocate buffer
glBufferData(GL_ARRAY_BUFFER, sizeof(pos)+sizeof(uv), NULL, GL_STATIC_DRAW);
//Fill VBO
glBufferSubData(GL_ARRAY_BUFFER, 0, sizeof(pos), pos);
glBufferSubData(GL_ARRAY_BUFFER, 8 * sizeof(float), sizeof(uv), uv);
//Fill attributes and uniforms
glEnableVertexAttribArray(0);
glVertexAttribPointer(0, 2, GL_FLOAT, GL_FALSE, (sizeof(float)* 2), (void*)0);
glEnableVertexAttribArray(1);
glVertexAttribPointer(1, 2, GL_FLOAT, GL_FALSE, (sizeof(float)* 2), (GLvoid*)(sizeof(float)* 8));
glUniform1i(s->uniform("tex"), 0);
s->disable();
//unbind buffer
glBindBuffer(GL_ARRAY_BUFFER, 0);
glBindVertexArray(0);
}
//Setters
void TextureViewer::setTexture(GLuint tex) {
this->texture = tex;
}
//Getters
GLuint TextureViewer::getTexture() {
return this->texture;
}

View File

@ -1,57 +0,0 @@
#define GLM_ENABLE_EXPERIMENTAL
#ifndef CTEXTUREVIEWER_H
#define CTEXTUREVIEWER_H
#include <iostream>
#include <map>
#include <vector>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/type_ptr.hpp>
#include "Loader.h"
/*
* Simple class, which will render texture on screen
*/
class TextureViewer
{
private:
GLuint texture;
//VBO - don't need EBO, i'll use glDrawArrays()
GLuint VBO;
//VAO - needed for glDrawArrays()
GLuint VAO;
ShaderProgram * s;
//Default shaders
std::string vs;
std::string fs;
bool depth;
void setUpShaders();
public:
TextureViewer();
TextureViewer(GLuint tex, std::string vs, std::string fs);
void draw();
//Setters
void setTexture(GLuint tex);
void setDepthOnly(bool depth);
//Getters
GLuint getTexture();
~TextureViewer();
};
#endif

View File

@ -1,118 +0,0 @@
#include "fboManager.h"
#include <iostream>
FboManager::FboManager() {
useRenderDepthBuffer = false;
attachmentCount = 0;
/*for(int i=0;i<5;i++) {
mrt[i] = GL_COLOR_ATTACHMENT0+i;
}*/
}
FboManager::~FboManager() {
glDeleteFramebuffers(1, &_fboId);
if(useRenderDepthBuffer) {
glDeleteRenderbuffers(1, &_renderDepthBufferId);
}
}
//create FBO
void FboManager::initFbo() {
glGenFramebuffers(1, &_fboId);
}
//generate and bind depth buffer
void FboManager::genRenderDepthBuffer(unsigned w, unsigned h) {
glGenRenderbuffers(1,&_renderDepthBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, _renderDepthBufferId);
glRenderbufferStorage(GL_RENDERBUFFER,GL_DEPTH_COMPONENT,w,h);
glBindRenderbuffer(GL_RENDERBUFFER, 0);
}
//bind depth buffer
void FboManager::bindRenderDepthBuffer() {
glBindFramebuffer(GL_FRAMEBUFFER,_fboId);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER,_renderDepthBufferId);
//glBindFramebuffer(GL_FRAMEBUFFER,0);
}
void FboManager::setDrawBuffers() {
glDrawBuffers(attachmentCount, mrt);
}
void FboManager::bindToFbo(GLenum type, GLenum texture, GLuint textureId) {
glBindFramebuffer(GL_FRAMEBUFFER,_fboId);
glFramebufferTexture2D(GL_FRAMEBUFFER,type,texture,textureId,0);
if(type != GL_DEPTH_ATTACHMENT) {
mrt[attachmentCount] = type;
attachmentCount += 1;
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
}
//glBindFramebuffer(GL_FRAMEBUFFER,0);
}
void FboManager::bind3DTextureToFbo(GLenum type, GLuint textureId) {
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
glFramebufferTexture(GL_FRAMEBUFFER, type, textureId, 0);
//glFramebufferTexture3D(GL_FRAMEBUFFER, type, GL_TEXTURE_3D, textureId, 0, 0);
if (type != GL_DEPTH_ATTACHMENT) {
mrt[attachmentCount] = type;
attachmentCount += 1;
glDrawBuffer(GL_NONE);
glReadBuffer(GL_NONE);
}
}
GLuint FboManager::getFboId() {
return _fboId;
}
bool FboManager::checkFboStatus() {
// check FBO status
GLenum status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
switch(status)
{
case GL_FRAMEBUFFER_COMPLETE_EXT:
std::cout << "Framebuffer complete." << std::endl;
return true;
case GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Attachment is NOT complete." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT_EXT:
std::cout << "[ERROR] Framebuffer incomplete: No image is attached to FBO." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Attached images have different dimensions." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_FORMATS_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Color attached images have different internal formats." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Draw buffer." << std::endl;
return false;
case GL_FRAMEBUFFER_INCOMPLETE_READ_BUFFER_EXT:
std::cout << "[ERROR] Framebuffer incomplete: Read buffer." << std::endl;
return false;
case GL_FRAMEBUFFER_UNSUPPORTED_EXT:
std::cout << "[ERROR] Unsupported by FBO implementation." << std::endl;
return false;
default:
std::cout << "[ERROR] Unknow error." << std::endl;
return false;
}
}

View File

@ -1,49 +0,0 @@
/*
* File: fboManager.h
* Desc: Jednoduchy "manager" pro FBO objekty
*
*/
#define GLM_ENABLE_EXPERIMENTAL
#ifndef FBOMANAGER_H
#define FBOMANAGER_H
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/type_ptr.hpp>
class FboManager {
public:
FboManager();
~FboManager();
//check fbo status
bool checkFboStatus();
//create a renderbuffer object
void genRenderDepthBuffer(unsigned w, unsigned h);
//bind a renderbuffer object
void bindRenderDepthBuffer();
void bindToFbo(GLenum type, GLenum texture, GLuint textureId);
void bind3DTextureToFbo(GLenum type, GLuint textureId);
void initFbo();
void setDrawBuffers();
GLuint getFboId();
private:
GLuint _fboId;
GLuint _renderDepthBufferId;
bool useRenderDepthBuffer;
unsigned attachmentCount;
GLenum mrt[6];
};
#endif

View File

@ -1,101 +0,0 @@
#include "textureManager.h"
#define MAX_GRID_SIZE 32
TextureManager::TextureManager() : clearTextureExtension(true) {
}
TextureManager::~TextureManager() {
textures.clear();
}
void TextureManager::add(const string& texture) {
GLuint tmpId;
glGenTextures(1, &tmpId);
textures[texture] = tmpId;
}
void TextureManager::createTexture(const string& texture, const string filePath,unsigned w, unsigned h, GLuint filter, GLuint type, GLuint type_2, bool depth = false)
{
// SDL_Surface *surface;
GLuint textureid;
int mode;
add(texture);
glBindTexture(GL_TEXTURE_2D, textures[texture]);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
//glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//No image data - for frameBuffer
if(filePath.empty()) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexImage2D(GL_TEXTURE_2D, 0 ,type, w, h, 0, type_2, GL_FLOAT, 0);
glTexImage2D(GL_TEXTURE_2D, 0 ,type, w, h, 0, type_2, GL_FLOAT, 0);
if (depth) {
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC, GL_LEQUAL);
//glTexParameteri(GL_TEXTURE_2D, GL_DEPTH_TEXTURE_MODE, GL_LUMINANCE);
}
}
}
void TextureManager::createRGBA16F3DTexture(const string& texture, glm::vec3 dim, GLuint filter, GLuint wrap) {
GLuint tex;
add(texture);
glBindTexture(GL_TEXTURE_3D, textures[texture]);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap);
//glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F, w, h, d, 0, GL_RGBA, GL_FLOAT, NULL);
//glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F, w, h, d, 0, GL_RGBA, GL_FLOAT, &emptyData[0]);
std::vector<GLfloat> emptyData(dim.x * dim.y * dim.z * sizeof(float), 0.0);
glBindTexture(GL_TEXTURE_3D, textures[texture]);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F, dim.x, dim.y, dim.z, 0, GL_RGBA, GL_FLOAT, &emptyData[0]);
glBindTexture(GL_TEXTURE_3D, 0);
//clear3Dtexture(textures[texture], dim);
//glBindTexture(GL_TEXTURE_3D, 0);
}
void TextureManager::clear3Dtexture(GLuint texture) {
if (clearTextureExtension) {
GLfloat data[4] = { 0.0f, 0.0f, 0.0f, 0.0f };
glClearTexImage(texture, 0, GL_RGBA, GL_FLOAT, &data[0]);
}
else {
//MUCH SLOWER version, but should work on version lower than 4.4
std::vector<GLfloat> emptyData(MAX_GRID_SIZE * MAX_GRID_SIZE * MAX_GRID_SIZE * sizeof(float), 0.0);
glBindTexture(GL_TEXTURE_3D, texture);
//glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA16F, MAX_GRID_SIZE, MAX_GRID_SIZE, MAX_GRID_SIZE, 0, GL_RGBA, GL_FLOAT, &emptyData[0]);
//or
glTexSubImage3D(GL_TEXTURE_3D, 0, 0,0,0, MAX_GRID_SIZE, MAX_GRID_SIZE, MAX_GRID_SIZE, GL_RGBA, GL_FLOAT, &emptyData[0]);
glBindTexture(GL_TEXTURE_3D, 0);
}
}
void TextureManager::createRGBA3DTexture(const string& texture, glm::vec3 dim, GLuint filter, GLuint wrap) {
GLuint tex;
add(texture);
glBindTexture(GL_TEXTURE_3D, textures[texture]);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MAG_FILTER, filter);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_MIN_FILTER, filter);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_S, wrap);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_T, wrap);
glTexParameteri(GL_TEXTURE_3D, GL_TEXTURE_WRAP_R, wrap);
glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA, dim.x, dim.y, dim.z, 0, GL_RGBA, GL_FLOAT, NULL);
//glBindTexture(GL_TEXTURE_3D, 0);
}
GLuint TextureManager::operator[] (const string& texture) {
return textures[texture];
}

View File

@ -1,41 +0,0 @@
#define GLM_ENABLE_EXPERIMENTAL
#ifndef TEXTUREMANAGER_H
#define TEXTUREMANAGER_H
#include <iostream>
#include <map>
#include <vector>
#include <GL/glew.h>
#include <glm/glm.hpp>
#include <glm/gtc/matrix_transform.hpp>
#include <glm/gtx/rotate_vector.hpp>
#include <glm/gtc/type_ptr.hpp>
using namespace std;
class TextureManager {
public:
TextureManager();
~TextureManager();
GLuint operator[](const string& texture);
void add(const string& texture);
void createTexture(const string& texture, const string filePath, unsigned w, unsigned h,
GLuint filter, GLuint type, GLuint type_2, bool depth);
void createRGBA16F3DTexture(const string& texture, glm::vec3 dim, GLuint filter, GLuint wrap);
void createRGBA3DTexture(const string& texture, glm::vec3 dim, GLuint filter, GLuint wrap);
void clear3Dtexture(GLuint texture);
void setClearTextureExtension(bool v) {
clearTextureExtension = v;
}
private:
map<string,GLuint> textures;
bool clearTextureExtension;
};
#endif

View File

@ -6,116 +6,7 @@ out vec4 final_color;
uniform sampler2D tex;
subroutine vec4 shading_t(vec4 color);
subroutine uniform shading_t Shading;
const float f = 1.0 / 300.0;
vec2 offsets[9] = vec2[](
vec2(-f, f), vec2(0.0, f), vec2(f, f),
vec2(-f, 0.0), vec2(0.0, 0.0), vec2(f, 0.0),
vec2(-f, -f), vec2(0.0, -f), vec2(f, -f)
);
subroutine(shading_t)
vec4 absolutely_no_postprocess(vec4 color)
{
return color;
}
subroutine(shading_t)
vec4 sepia(vec4 color)
{
return vec4(color.r * .393 + color.g * .769 + color.b * .189,
color.r * .349 + color.g * .686 + color.b * .168,
color.r * .272 + color.g * .534 + color.b * .131, 1.0);
}
subroutine(shading_t)
vec4 grayscale(vec4 color)
{
float average = color.r * 0.2126 + color.g * 0.7152 + color.b * 0.0722;
return vec4(average, average, average, 1);
}
subroutine(shading_t)
vec4 depthing(vec4 color)
{
float zNear = 2.1f; // zNear of your perspective projection
float zFar = 40.0f; // zFar of your perspective projection
float depth = color.x;
float r = (zNear * 2.0) / (zFar + zNear - depth * (zFar - zNear));
return vec4(r, r, r, 1);
}
subroutine(shading_t)
vec4 blurring(vec4 color)
{
float blur_kernel[9] = float[](
1.0 / 16, 2.0 / 16, 1.0 / 16,
2.0 / 16, 4.0 / 16, 2.0 / 16,
1.0 / 16, 2.0 / 16, 1.0 / 16
);
vec3 texblur = vec3(0,0,0);
for (int i = 0; i < 9; i++)
texblur += vec3(texture(tex, uv + offsets[i]).rgb * blur_kernel[i]);
return vec4(texblur, 1);
}
subroutine(shading_t)
vec4 sharpening(vec4 color)
{
float sharp_kernel[9] = float[](
-1, -1, -1,
-1, 9, -1,
-1, -1, -1
);
vec3 texsharp = vec3(0,0,0);
for (uint i = 0; i < 9; i++)
texsharp += texture(tex, uv + offsets[i]).rgb * sharp_kernel[i];
return vec4(texsharp, 1);
}
subroutine(shading_t)
vec4 sobel_filter(vec4 color)
{
float sobel_x[9] = float[](
-1, 0, 1,
-2, 0, 2,
-1, 0, 1
);
float sobel_y[9] = float[](
-1, -2, -1,
0, 0, 0,
1, 2, 1
);
vec3 vec_x = vec3(0);
vec3 vec_y = vec3(0);
for (int i = 0; i < 9; i++)
{
vec_x += texture(tex, uv + offsets[i]).rgb * sobel_x[i];
vec_y += texture(tex, uv + offsets[i]).rgb * sobel_y[i];
}
vec4 sobeled = vec4(sqrt(vec_x * vec_x + vec_y * vec_y), 1);
return grayscale(sobeled);
}
subroutine(shading_t)
vec4 no_postprocess(vec4 color)
{
return color;
}
void main()
{
final_color = texture(tex, uv).rgba;
final_color = Shading(final_color);
final_color = texture(tex, uv).rgba;
}