Compare commits
No commits in common. "master" and "DeferredShading" have entirely different histories.
master
...
DeferredSh
@ -95,7 +95,7 @@
|
|||||||
<GenerateDebugInformation>true</GenerateDebugInformation>
|
<GenerateDebugInformation>true</GenerateDebugInformation>
|
||||||
<SubSystem>Console</SubSystem>
|
<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>
|
<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;FreeImage.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
<AdditionalDependencies>assimp.lib;SOIL.lib;glfw3.lib;glew32.lib;opengl32.lib;%(AdditionalDependencies)</AdditionalDependencies>
|
||||||
</Link>
|
</Link>
|
||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
|
||||||
@ -147,6 +147,7 @@
|
|||||||
</ItemDefinitionGroup>
|
</ItemDefinitionGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClCompile Include="Dataset.cpp" />
|
<ClCompile Include="Dataset.cpp" />
|
||||||
|
<ClCompile Include="fboManager.cpp" />
|
||||||
<ClCompile Include="imgui\imgui.cpp" />
|
<ClCompile Include="imgui\imgui.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_demo.cpp" />
|
<ClCompile Include="imgui\imgui_demo.cpp" />
|
||||||
<ClCompile Include="imgui\imgui_draw.cpp" />
|
<ClCompile Include="imgui\imgui_draw.cpp" />
|
||||||
@ -158,12 +159,16 @@
|
|||||||
<ClCompile Include="Multipass.cpp" />
|
<ClCompile Include="Multipass.cpp" />
|
||||||
<ClCompile Include="MyGLWindow.cpp" />
|
<ClCompile Include="MyGLWindow.cpp" />
|
||||||
<ClCompile Include="Shader.cpp" />
|
<ClCompile Include="Shader.cpp" />
|
||||||
|
<ClCompile Include="Skybox.cpp" />
|
||||||
<ClCompile Include="Source.cpp" />
|
<ClCompile Include="Source.cpp" />
|
||||||
<ClCompile Include="Texture.cpp" />
|
<ClCompile Include="Texture.cpp" />
|
||||||
|
<ClCompile Include="textureManager.cpp" />
|
||||||
|
<ClCompile Include="TextureViewer.cpp" />
|
||||||
<ClCompile Include="Viewer.cpp" />
|
<ClCompile Include="Viewer.cpp" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<ClInclude Include="Dataset.h" />
|
<ClInclude Include="Dataset.h" />
|
||||||
|
<ClInclude Include="fboManager.h" />
|
||||||
<ClInclude Include="imgui\imconfig.h" />
|
<ClInclude Include="imgui\imconfig.h" />
|
||||||
<ClInclude Include="imgui\imgui.h" />
|
<ClInclude Include="imgui\imgui.h" />
|
||||||
<ClInclude Include="imgui\imgui_impl_glfw.h" />
|
<ClInclude Include="imgui\imgui_impl_glfw.h" />
|
||||||
@ -181,7 +186,10 @@
|
|||||||
<ClInclude Include="MyGLWindow.h" />
|
<ClInclude Include="MyGLWindow.h" />
|
||||||
<ClInclude Include="SceneContext.h" />
|
<ClInclude Include="SceneContext.h" />
|
||||||
<ClInclude Include="Shader.h" />
|
<ClInclude Include="Shader.h" />
|
||||||
|
<ClInclude Include="Skybox.h" />
|
||||||
<ClInclude Include="Texture.h" />
|
<ClInclude Include="Texture.h" />
|
||||||
|
<ClInclude Include="textureManager.h" />
|
||||||
|
<ClInclude Include="TextureViewer.h" />
|
||||||
<ClInclude Include="Viewer.h" />
|
<ClInclude Include="Viewer.h" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -193,12 +201,8 @@
|
|||||||
<None Include="fog.frag" />
|
<None Include="fog.frag" />
|
||||||
<None Include="fog.vert" />
|
<None Include="fog.vert" />
|
||||||
<None Include="base_light.vert" />
|
<None Include="base_light.vert" />
|
||||||
<None Include="light_pov.frag" />
|
|
||||||
<None Include="light_pov.vert" />
|
|
||||||
<None Include="nmap.frag" />
|
<None Include="nmap.frag" />
|
||||||
<None Include="nmap.vert" />
|
<None Include="nmap.vert" />
|
||||||
<None Include="shadow_light.frag" />
|
|
||||||
<None Include="shadow_light.vert" />
|
|
||||||
<None Include="skybox.frag" />
|
<None Include="skybox.frag" />
|
||||||
<None Include="skybox.vert" />
|
<None Include="skybox.vert" />
|
||||||
<None Include="spotlight.frag" />
|
<None Include="spotlight.frag" />
|
||||||
@ -229,7 +233,6 @@
|
|||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="brick1.jpg" />
|
<Image Include="brick1.jpg" />
|
||||||
<Image Include="default.jpg" />
|
|
||||||
<Image Include="earth.jpg" />
|
<Image Include="earth.jpg" />
|
||||||
<Image Include="moss.png" />
|
<Image Include="moss.png" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|||||||
@ -22,8 +22,8 @@
|
|||||||
<Filter Include="Models">
|
<Filter Include="Models">
|
||||||
<UniqueIdentifier>{af32f844-b061-4424-a685-e3f537232cf8}</UniqueIdentifier>
|
<UniqueIdentifier>{af32f844-b061-4424-a685-e3f537232cf8}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
<Filter Include="Shaders\PPShaders">
|
<Filter Include="MankyuCode">
|
||||||
<UniqueIdentifier>{be4b14ab-faab-4412-8a5b-ce9c1510772f}</UniqueIdentifier>
|
<UniqueIdentifier>{b0c228ca-8e29-48df-a9f6-59fb58accad5}</UniqueIdentifier>
|
||||||
</Filter>
|
</Filter>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -69,6 +69,18 @@
|
|||||||
<ClCompile Include="Texture.cpp">
|
<ClCompile Include="Texture.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
|
<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">
|
<ClCompile Include="Multipass.cpp">
|
||||||
<Filter>Source Files</Filter>
|
<Filter>Source Files</Filter>
|
||||||
</ClCompile>
|
</ClCompile>
|
||||||
@ -131,6 +143,18 @@
|
|||||||
<ClInclude Include="Texture.h">
|
<ClInclude Include="Texture.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<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">
|
<ClInclude Include="Multipass.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
@ -193,27 +217,23 @@
|
|||||||
<None Include="skybox.frag">
|
<None Include="skybox.frag">
|
||||||
<Filter>Shaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="light_pov.frag" />
|
|
||||||
<None Include="light_pov.vert" />
|
|
||||||
<None Include="shadow_light.frag" />
|
|
||||||
<None Include="shadow_light.vert" />
|
|
||||||
<None Include="textureViewer.frag">
|
|
||||||
<Filter>Shaders\PPShaders</Filter>
|
|
||||||
</None>
|
|
||||||
<None Include="textureViewer.vert">
|
<None Include="textureViewer.vert">
|
||||||
<Filter>Shaders\PPShaders</Filter>
|
<Filter>MankyuCode</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="DSLightPass.frag">
|
<None Include="textureViewer.frag">
|
||||||
<Filter>Shaders\PPShaders</Filter>
|
<Filter>MankyuCode</Filter>
|
||||||
</None>
|
|
||||||
<None Include="DSGeometryPass.frag">
|
|
||||||
<Filter>Shaders\PPShaders</Filter>
|
|
||||||
</None>
|
</None>
|
||||||
<None Include="DSGeometryPass.vert">
|
<None Include="DSGeometryPass.vert">
|
||||||
<Filter>Shaders\PPShaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="DSGeometryPass.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
<None Include="DSLightPass.vert">
|
<None Include="DSLightPass.vert">
|
||||||
<Filter>Shaders\PPShaders</Filter>
|
<Filter>Shaders</Filter>
|
||||||
|
</None>
|
||||||
|
<None Include="DSLightPass.frag">
|
||||||
|
<Filter>Shaders</Filter>
|
||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
@ -226,8 +246,5 @@
|
|||||||
<Image Include="moss.png">
|
<Image Include="moss.png">
|
||||||
<Filter>Resource Files</Filter>
|
<Filter>Resource Files</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
<Image Include="default.jpg">
|
|
||||||
<Filter>Resource Files</Filter>
|
|
||||||
</Image>
|
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
@ -1,18 +1,10 @@
|
|||||||
#version 440
|
#version 440
|
||||||
layout (location = 0) out vec3 gPosition;
|
//Copy of simple.frag
|
||||||
layout (location = 1) out vec3 gNormal;
|
|
||||||
layout (location = 2) out vec4 gAlbedoSpec;
|
|
||||||
|
|
||||||
in vec2 TexCoords;
|
in vec3 f_color;
|
||||||
in vec3 FragPos;
|
out vec4 FragColors;
|
||||||
in vec3 Normal;
|
|
||||||
|
|
||||||
uniform sampler2D tex;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
gPosition = FragPos;
|
FragColors = vec4(f_color, 1.f);
|
||||||
gNormal = normalize(Normal);
|
|
||||||
gAlbedoSpec.rgb = texture(tex, TexCoords).rgb;
|
|
||||||
gAlbedoSpec.a = 1;
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,22 +1,18 @@
|
|||||||
#version 440
|
#version 440
|
||||||
|
// Copy of simple.vert
|
||||||
|
|
||||||
layout(location=0) in vec3 coord3d;
|
layout(location=0) in vec3 coord3d;
|
||||||
layout(location=1) in vec3 v_normal;
|
layout(location=1) in vec3 v_normal;
|
||||||
layout(location=2) in vec3 v_color;
|
layout(location=2) in vec3 v_color;
|
||||||
layout(location=3) in vec2 v_texmap;
|
layout(location=3) in vec2 v_texmap;
|
||||||
|
|
||||||
out vec2 TexCoords;
|
|
||||||
out vec3 FragPos;
|
out vec3 f_color;
|
||||||
out vec3 Normal;
|
|
||||||
|
|
||||||
uniform mat4 mvp;
|
uniform mat4 mvp;
|
||||||
uniform mat3 NormalMatrix;
|
|
||||||
uniform mat4 ModelMatrix;
|
|
||||||
|
|
||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
Normal = NormalMatrix * v_normal;
|
f_color = v_color;
|
||||||
TexCoords = v_texmap;
|
|
||||||
FragPos = (ModelMatrix * vec4(coord3d, 1.0f)).xyz;
|
|
||||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||||
}
|
}
|
||||||
@ -1,44 +1,10 @@
|
|||||||
#version 440
|
#version 440
|
||||||
out vec4 FragColor;
|
//Copy of simple.frag
|
||||||
|
|
||||||
in vec2 uv;
|
in vec3 f_color;
|
||||||
|
out vec4 FragColors;
|
||||||
uniform sampler2D pos_tex;
|
|
||||||
uniform sampler2D normal_tex;
|
|
||||||
uniform sampler2D color_tex;
|
|
||||||
|
|
||||||
struct Light {
|
|
||||||
vec3 Position;
|
|
||||||
vec3 Color;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform int NLights;
|
|
||||||
uniform Light lights[64];
|
|
||||||
|
|
||||||
uniform vec3 view_pos;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
vec3 FragPos = texture(pos_tex, uv).rgb;
|
FragColors = vec4(f_color, 1.f);
|
||||||
vec3 Normal = texture(normal_tex, uv).rgb;
|
|
||||||
vec3 Albedo = texture(color_tex, uv).rgb;
|
|
||||||
float Specular = 0.5f;
|
|
||||||
|
|
||||||
// then calculate lighting as usual
|
|
||||||
vec3 lighting = Albedo * 0.1; // hard-coded ambient component
|
|
||||||
vec3 viewDir = normalize(view_pos - FragPos);
|
|
||||||
for (int i = 0; i < NLights; ++i)
|
|
||||||
{
|
|
||||||
vec3 L = normalize(lights[i].Position.xyz - FragPos);
|
|
||||||
vec3 V = normalize(view_pos - FragPos);
|
|
||||||
vec3 H = normalize(V + L);
|
|
||||||
|
|
||||||
vec3 diffuse = max(dot(Normal, L), 0.0) * Albedo * lights[i].Color;
|
|
||||||
// specular
|
|
||||||
float spec = pow(max(dot(Normal, H), 0.0), 16.0);
|
|
||||||
vec3 specular = lights[i].Color * spec * Specular;
|
|
||||||
lighting += diffuse + specular;
|
|
||||||
}
|
|
||||||
|
|
||||||
FragColor = vec4(lighting, 1.0);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,12 +1,18 @@
|
|||||||
#version 430
|
#version 440
|
||||||
|
// Copy of simple.vert
|
||||||
|
|
||||||
layout(location = 0) in vec2 vPosition;
|
layout(location=0) in vec3 coord3d;
|
||||||
layout(location = 1) in vec2 vUV;
|
layout(location=1) in vec3 v_normal;
|
||||||
|
layout(location=2) in vec3 v_color;
|
||||||
|
layout(location=3) in vec2 v_texmap;
|
||||||
|
|
||||||
out vec2 uv;
|
|
||||||
|
|
||||||
void main()
|
out vec3 f_color;
|
||||||
|
|
||||||
|
uniform mat4 mvp;
|
||||||
|
|
||||||
|
void main(void)
|
||||||
{
|
{
|
||||||
gl_Position = vec4(vPosition,0.0,1.0);
|
f_color = v_color;
|
||||||
uv = vUV;
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||||
}
|
}
|
||||||
@ -107,12 +107,6 @@ void Dataset::simpleFloor()
|
|||||||
|
|
||||||
colors = { { 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },
|
colors = { { 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },
|
||||||
{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 } };
|
{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 },{ 0.7, 0.7, 0.7 } };
|
||||||
|
|
||||||
tex_mapping = {
|
|
||||||
{ 0.0f, 0.0f },{ 1.0f, 0.0f },{ 1.0f, 1.0f }, // one triangle
|
|
||||||
{ 1.0f, 1.0f },{ 0.0f, 1.0f },{ 0.0f, 0.0f } //the other triangle
|
|
||||||
};
|
|
||||||
|
|
||||||
genNormals();
|
genNormals();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -1,37 +0,0 @@
|
|||||||
#version 430
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
in vec2 TexCoords;
|
|
||||||
|
|
||||||
uniform sampler2D gPosition;
|
|
||||||
uniform sampler2D gNormal;
|
|
||||||
uniform sampler2D gAlbedoSpec;
|
|
||||||
|
|
||||||
subroutine vec4 shading_t();
|
|
||||||
subroutine uniform shading_t Shading;
|
|
||||||
|
|
||||||
subroutine(shading_t)
|
|
||||||
vec4 DisplayAlbedo()
|
|
||||||
{
|
|
||||||
vec3 Albedo = texture(gAlbedoSpec, TexCoords).rgb;
|
|
||||||
return vec4(Albedo, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
subroutine(shading_t)
|
|
||||||
vec4 DisplayPositions()
|
|
||||||
{
|
|
||||||
vec3 FragPos = texture(gPosition, TexCoords).rgb;
|
|
||||||
return vec4(FragPos, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
subroutine(shading_t)
|
|
||||||
vec4 DisplayNormals()
|
|
||||||
{
|
|
||||||
vec3 Normal = texture(gNormal, TexCoords).rgb;
|
|
||||||
return vec4(Normal, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
FragColor = Shading();
|
|
||||||
}
|
|
||||||
@ -1,12 +0,0 @@
|
|||||||
#version 430
|
|
||||||
|
|
||||||
layout(location = 0) in vec2 vPosition;
|
|
||||||
layout(location = 1) in vec2 vUV;
|
|
||||||
|
|
||||||
out vec2 TexCoords;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
gl_Position = vec4(vPosition,0.0,1.0);
|
|
||||||
TexCoords = vUV;
|
|
||||||
}
|
|
||||||
@ -21,10 +21,3 @@ Light::Light() : location(glm::vec4(0)), intensity(glm::vec3(1))
|
|||||||
Light::~Light()
|
Light::~Light()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Light::toString()
|
|
||||||
{
|
|
||||||
return "(" + std::to_string(location.x) + ", " +
|
|
||||||
std::to_string(location.y) + ", " +
|
|
||||||
std::to_string(location.z) + ")";
|
|
||||||
}
|
|
||||||
@ -2,7 +2,6 @@
|
|||||||
|
|
||||||
#include "glm/vec3.hpp"
|
#include "glm/vec3.hpp"
|
||||||
#include "glm/vec4.hpp"
|
#include "glm/vec4.hpp"
|
||||||
#include <string>
|
|
||||||
|
|
||||||
class Light
|
class Light
|
||||||
{
|
{
|
||||||
@ -19,8 +18,6 @@ public:
|
|||||||
float spot_exponent, glm::vec4 lookAt);
|
float spot_exponent, glm::vec4 lookAt);
|
||||||
~Light();
|
~Light();
|
||||||
|
|
||||||
std::string toString();
|
|
||||||
|
|
||||||
bool activated = true;
|
bool activated = true;
|
||||||
LightType type;
|
LightType type;
|
||||||
glm::vec3 intensity;
|
glm::vec3 intensity;
|
||||||
|
|||||||
@ -96,9 +96,7 @@ private:
|
|||||||
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &shaderStatus);
|
glGetShaderiv(shaderId, GL_COMPILE_STATUS, &shaderStatus);
|
||||||
if (shaderStatus == GL_FALSE)
|
if (shaderStatus == GL_FALSE)
|
||||||
{
|
{
|
||||||
std::string err = getInfoLog(ObjectType::SHADER, shaderId);
|
throw std::runtime_error(shaderTypeString + " compilation failed: " + getInfoLog(ObjectType::SHADER, shaderId));
|
||||||
std::cout << err << std::endl;
|
|
||||||
throw std::runtime_error(shaderTypeString + " compilation failed: " + err);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -378,7 +376,6 @@ public:
|
|||||||
// Check to ensure that the shader contains a uniform with this name
|
// Check to ensure that the shader contains a uniform with this name
|
||||||
if (uniformMap[uniformName] == -1)
|
if (uniformMap[uniformName] == -1)
|
||||||
{
|
{
|
||||||
int error = glGetError();
|
|
||||||
throw std::runtime_error("Could not add uniform: " + uniformName + " - location returned -1.");
|
throw std::runtime_error("Could not add uniform: " + uniformName + " - location returned -1.");
|
||||||
}
|
}
|
||||||
else // Valid uniform location? Inform user if we're in debug mode.
|
else // Valid uniform location? Inform user if we're in debug mode.
|
||||||
|
|||||||
@ -20,6 +20,7 @@ public:
|
|||||||
|
|
||||||
void glTranslate(float x, float y, float z)
|
void glTranslate(float x, float y, float z)
|
||||||
{
|
{
|
||||||
|
|
||||||
glm::mat4 Trans = glm::translate(glm::mat4(1.0f), glm::vec3(x, y, z));
|
glm::mat4 Trans = glm::translate(glm::mat4(1.0f), glm::vec3(x, y, z));
|
||||||
modelstack.top() = modelstack.top() * Trans;
|
modelstack.top() = modelstack.top() * Trans;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -278,8 +278,9 @@ Mesh::MeshEntry::~MeshEntry() {
|
|||||||
/**
|
/**
|
||||||
* Renders this MeshEntry
|
* Renders this MeshEntry
|
||||||
**/
|
**/
|
||||||
void Mesh::MeshEntry::render(SceneContext &ctx, Shader &shd) {
|
void Mesh::MeshEntry::render(SceneContext &ctx, Shader *shd) {
|
||||||
|
|
||||||
|
textureBinding(shd);
|
||||||
glBindVertexArray(vao);
|
glBindVertexArray(vao);
|
||||||
if (renderType == NO_INDEX)
|
if (renderType == NO_INDEX)
|
||||||
{
|
{
|
||||||
@ -291,15 +292,38 @@ void Mesh::MeshEntry::render(SceneContext &ctx, Shader &shd) {
|
|||||||
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
||||||
glDrawElements(GL_TRIANGLES, size / sizeof(unsigned int), GL_UNSIGNED_INT, NULL);
|
glDrawElements(GL_TRIANGLES, size / sizeof(unsigned int), GL_UNSIGNED_INT, NULL);
|
||||||
}
|
}
|
||||||
|
textureUnbinding();
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mesh::MeshEntry::textureBinding(Shader * shd)
|
||||||
|
{
|
||||||
|
for (GLuint i = 0; i < textures.size(); i++)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
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());
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mesh::MeshEntry::textureUnbinding()
|
||||||
|
{
|
||||||
|
for (GLuint i = 0; i < textures.size(); i++)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mesh constructor, loads the specified filename if supported by Assimp
|
* Mesh constructor, loads the specified filename if supported by Assimp
|
||||||
**/
|
**/
|
||||||
Mesh::Mesh(const char *filename, std::string vert_shd, std::string frag_shd)
|
Mesh::Mesh(const char *filename, Shader *sh)
|
||||||
{
|
{
|
||||||
shader = std::make_shared<Shader>(vert_shd, frag_shd);
|
shader = sh;
|
||||||
|
|
||||||
std::string fullname;
|
std::string fullname;
|
||||||
fullname = std::string("./Models/")+ std::string(filename);
|
fullname = std::string("./Models/")+ std::string(filename);
|
||||||
directory = fullname;
|
directory = fullname;
|
||||||
@ -314,32 +338,35 @@ Mesh::Mesh(const char *filename, std::string vert_shd, std::string frag_shd)
|
|||||||
if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
|
if (!scene || scene->mFlags == AI_SCENE_FLAGS_INCOMPLETE || !scene->mRootNode) // if is Not Zero
|
||||||
{
|
{
|
||||||
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
std::cout << "ERROR::ASSIMP:: " << importer.GetErrorString() << std::endl;
|
||||||
throw new std::exception(("Error loading mesh at the following location : " + fullname).c_str());
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
// Load all textures
|
||||||
meshEntries.push_back(new Mesh::MeshEntry(scene->mMeshes[i], scene, this));
|
|
||||||
|
|
||||||
for (unsigned int i = 0; i < scene->mNumMaterials; i++)
|
for (unsigned int i = 0; i < scene->mNumMaterials; i++)
|
||||||
{
|
{
|
||||||
aiMaterial* material = scene->mMaterials[i];
|
aiMaterial* material = scene->mMaterials[i];
|
||||||
if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0)
|
if (material->GetTextureCount(aiTextureType_DIFFUSE) > 0) { //we only care diffuse texture
|
||||||
{
|
|
||||||
aiString Path;
|
aiString Path;
|
||||||
if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL,
|
if (material->GetTexture(aiTextureType_DIFFUSE, 0, &Path, NULL, NULL, NULL,
|
||||||
NULL, NULL) == AI_SUCCESS)
|
NULL, NULL) == AI_SUCCESS) {
|
||||||
{
|
|
||||||
std::string FullPath = directory + Path.data; //texture file
|
std::string FullPath = directory + Path.data; //texture file
|
||||||
textures.emplace("0", Texture(FullPath));
|
textures.emplace(FullPath, Texture(FullPath));
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Mesh::Mesh(Dataset &set, std::string vert_shd, std::string frag_shd)
|
|
||||||
|
|
||||||
|
for (unsigned int i = 0; i < scene->mNumMeshes; ++i) {
|
||||||
|
meshEntries.push_back(new Mesh::MeshEntry(scene->mMeshes[i], scene, this));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
Mesh::Mesh(Dataset &set, Shader *sh)
|
||||||
{
|
{
|
||||||
shader = std::make_shared<Shader>(vert_shd, frag_shd);
|
shader = sh;
|
||||||
|
|
||||||
meshEntries.push_back(new Mesh::MeshEntry(set, this));
|
meshEntries.push_back(new Mesh::MeshEntry(set, this));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -355,9 +382,57 @@ Mesh::~Mesh(void)
|
|||||||
meshEntries.clear();
|
meshEntries.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mesh::enableCulling()
|
||||||
|
{
|
||||||
|
if (cullMode == NONE)
|
||||||
|
return;
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(cullMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mesh::disableCulling()
|
||||||
|
{
|
||||||
|
if (cullMode == NONE)
|
||||||
|
return;
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mesh::textureUnbinding()
|
||||||
|
{
|
||||||
|
for (GLuint i = 0; i < textures.size(); i++)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void Mesh::textureBinding(Shader *shd)
|
||||||
|
{
|
||||||
|
int nmap_counter = 0;
|
||||||
|
int i = 0;
|
||||||
|
for (std::map<std::string, Texture>::iterator it = textures.begin(); it != textures.end(); ++it)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0 + i);
|
||||||
|
glBindTexture(GL_TEXTURE_2D, it->second.tex_ref);
|
||||||
|
shd->applyTextureMaterial(it->second);
|
||||||
|
if (it->second.isNmap)
|
||||||
|
{
|
||||||
|
shd->addUniform("nmap", (int)i);
|
||||||
|
nmap_counter++;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
shd->addUniform("tex[" + std::to_string(i - nmap_counter) + "]", (int)i);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
if (textures.size() > 0)
|
||||||
|
shd->addUniform("TexCount", (int)textures.size() - nmap_counter);
|
||||||
|
}
|
||||||
|
|
||||||
void Mesh::draw(SceneContext &ctx) {
|
void Mesh::draw(SceneContext &ctx) {
|
||||||
|
|
||||||
shader->enable();
|
shader->enable();
|
||||||
|
textureBinding(shader);
|
||||||
|
enableCulling();
|
||||||
for (unsigned int i = 0; i < meshEntries.size(); ++i) {
|
for (unsigned int i = 0; i < meshEntries.size(); ++i) {
|
||||||
|
|
||||||
MeshEntry * m = meshEntries[i];
|
MeshEntry * m = meshEntries[i];
|
||||||
@ -367,29 +442,64 @@ void Mesh::draw(SceneContext &ctx) {
|
|||||||
model.glPushMatrix();
|
model.glPushMatrix();
|
||||||
effectTransformations();
|
effectTransformations();
|
||||||
|
|
||||||
|
//Retrieving material data from the vertex
|
||||||
|
|
||||||
|
float shininess = meshEntries.at(i)->shininessStrength;
|
||||||
|
glm::vec3 diffuse = glm::vec3(meshEntries.at(i)->dcolor.r, meshEntries.at(i)->dcolor.g, meshEntries.at(i)->dcolor.b);
|
||||||
|
glm::vec3 specular = glm::vec3(meshEntries.at(i)->scolor.r, meshEntries.at(i)->scolor.g, meshEntries.at(i)->scolor.b);
|
||||||
|
glm::vec3 ambient = glm::vec3(meshEntries.at(i)->acolor.r, meshEntries.at(i)->acolor.g, meshEntries.at(i)->acolor.b);
|
||||||
|
|
||||||
|
if (glm::length(ambient) == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
||||||
|
ambient = textures.begin()->second.mat.ka;
|
||||||
|
else if (glm::length(ambient) == 0)
|
||||||
|
ambient = glm::vec3(0.1, 0.1, 0.1);
|
||||||
|
|
||||||
|
if (glm::length(diffuse) == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
||||||
|
diffuse = textures.begin()->second.mat.ks;
|
||||||
|
else if (glm::length(diffuse) == 0)
|
||||||
|
diffuse = glm::vec3(0.9, 0.9, 0.9);
|
||||||
|
|
||||||
|
if (glm::length(specular) == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
||||||
|
specular = textures.begin()->second.mat.ks;
|
||||||
|
else if (glm::length(specular) == 0)
|
||||||
|
specular = glm::vec3(0.4, 0.4, 0.4);
|
||||||
|
|
||||||
|
if (shininess == 0 && textures.size() > 0 && textures.begin()->second.mat.enabled)
|
||||||
|
shininess = textures.begin()->second.mat.shininess;
|
||||||
|
else if (shininess == 0)
|
||||||
|
shininess = 150.0f;
|
||||||
|
|
||||||
|
shader->mat.ka = ambient;
|
||||||
|
shader->mat.kd = diffuse;
|
||||||
|
shader->mat.ks = specular;
|
||||||
|
shader->mat.shininess = shininess;
|
||||||
|
|
||||||
// Setting the space matrixes uniques to the object
|
// Setting the space matrixes uniques to the object
|
||||||
ctx.modelMatrix = model.getMatrix();
|
ctx.modelMatrix = model.getMatrix();
|
||||||
|
if (shader->uniformFlags & MVP_FLAG)
|
||||||
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
||||||
//ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
if (shader->uniformFlags & MODELVIEW_FLAG)
|
||||||
ctx.normalMatrix = glm::transpose(glm::inverse(glm::mat3(ctx.modelMatrix)));
|
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
||||||
|
if (shader->uniformFlags & NORMAL_MAT_FLAG)
|
||||||
|
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix)));
|
||||||
|
|
||||||
shader->addUniform("mvp", ctx.mvpMatrix);
|
//Sending the uniform data to the shader
|
||||||
shader->addUniform("NormalMatrix", ctx.normalMatrix);
|
|
||||||
shader->addUniform("ModelMatrix", ctx.modelMatrix);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, textures["0"].tex_ref);
|
|
||||||
|
|
||||||
meshEntries.at(i)->render(ctx, *shader);
|
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
|
shader->setUniforms(ctx);
|
||||||
|
|
||||||
|
meshEntries.at(i)->render(ctx, shader);
|
||||||
model.glPopMatrix();
|
model.glPopMatrix();
|
||||||
}
|
}
|
||||||
|
disableCulling();
|
||||||
|
textureUnbinding();
|
||||||
shader->disable();
|
shader->disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Mesh::assignTexture(Texture &texture)
|
||||||
|
{
|
||||||
|
//textures.emplace_back(texture);
|
||||||
|
}
|
||||||
|
|
||||||
void Mesh::effectTransformations()
|
void Mesh::effectTransformations()
|
||||||
{
|
{
|
||||||
for (auto pair : _transformations)
|
for (auto pair : _transformations)
|
||||||
|
|||||||
@ -60,13 +60,15 @@ public:
|
|||||||
MeshEntry(Dataset &set, Mesh *m);
|
MeshEntry(Dataset &set, Mesh *m);
|
||||||
~MeshEntry();
|
~MeshEntry();
|
||||||
Mesh * parent;
|
Mesh * parent;
|
||||||
void render(SceneContext &ctx, Shader &shd);
|
void render(SceneContext &ctx, Shader *shd);
|
||||||
|
private:
|
||||||
|
void textureBinding(Shader *shd);
|
||||||
|
void textureUnbinding();
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Mesh(const char *filename, std::string vert_shd, std::string frag_shd);
|
Mesh(const char *filename, Shader *sh);
|
||||||
Mesh(Dataset &dataset, std::string vert_shd, std::string frag_shd);
|
Mesh(Dataset &dataset, Shader *sh);
|
||||||
~Mesh(void);
|
~Mesh(void);
|
||||||
std::string directory;
|
std::string directory;
|
||||||
std::vector<MeshEntry*> meshEntries;
|
std::vector<MeshEntry*> meshEntries;
|
||||||
@ -75,6 +77,10 @@ public:
|
|||||||
private:
|
private:
|
||||||
std::vector<std::pair<glm::vec4, Transformation>> _transformations;
|
std::vector<std::pair<glm::vec4, Transformation>> _transformations;
|
||||||
|
|
||||||
|
void enableCulling();
|
||||||
|
void textureBinding(Shader *shd);
|
||||||
|
void textureUnbinding();
|
||||||
|
void disableCulling();
|
||||||
public:
|
public:
|
||||||
Model model;
|
Model model;
|
||||||
CullFace cullMode = NONE;
|
CullFace cullMode = NONE;
|
||||||
@ -91,7 +97,8 @@ public:
|
|||||||
void removeLastTransformations(int n);
|
void removeLastTransformations(int n);
|
||||||
glm::vec3 getPosition();
|
glm::vec3 getPosition();
|
||||||
|
|
||||||
std::shared_ptr<Shader> shader;
|
Shader *shader;
|
||||||
void draw(SceneContext &ctx);
|
void draw(SceneContext &ctx);
|
||||||
|
|
||||||
|
void assignTexture(Texture &texture);
|
||||||
};
|
};
|
||||||
|
Before Width: | Height: | Size: 562 KiB |
|
Before Width: | Height: | Size: 846 KiB |
|
Before Width: | Height: | Size: 386 KiB |
|
Before Width: | Height: | Size: 1.6 MiB |
|
Before Width: | Height: | Size: 51 KiB |
|
Before Width: | Height: | Size: 621 KiB |
|
Before Width: | Height: | Size: 840 KiB |
|
Before Width: | Height: | Size: 90 KiB |
|
Before Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 100 KiB |
|
Before Width: | Height: | Size: 86 KiB |
|
Before Width: | Height: | Size: 277 KiB |
|
Before Width: | Height: | Size: 63 KiB |
|
Before Width: | Height: | Size: 42 KiB |
|
Before Width: | Height: | Size: 570 KiB |
|
Before Width: | Height: | Size: 52 KiB |
|
Before Width: | Height: | Size: 5.8 KiB |
|
Before Width: | Height: | Size: 1.3 KiB |
|
Before Width: | Height: | Size: 3.2 KiB |
|
Before Width: | Height: | Size: 640 KiB |
|
Before Width: | Height: | Size: 976 KiB |
|
Before Width: | Height: | Size: 64 KiB |
|
Before Width: | Height: | Size: 1.7 MiB |
|
Before Width: | Height: | Size: 513 KiB |
|
Before Width: | Height: | Size: 729 KiB |
|
Before Width: | Height: | Size: 55 KiB |
|
Before Width: | Height: | Size: 1.5 MiB |
|
Before Width: | Height: | Size: 1.1 MiB |
|
Before Width: | Height: | Size: 1.3 MiB |
|
Before Width: | Height: | Size: 73 KiB |
|
Before Width: | Height: | Size: 1.7 MiB |
@ -1,79 +0,0 @@
|
|||||||
# 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
|
|
||||||
@ -1,8 +1,8 @@
|
|||||||
#include "Multipass.h"
|
#include "Multipass.h"
|
||||||
|
|
||||||
Multipass::Multipass()
|
Multipass::Multipass() : shader("textureViewer.vert", "textureViewer.frag")
|
||||||
{
|
{
|
||||||
shader = new Shader("textureViewer.vert", "textureViewer.frag");
|
|
||||||
_draw_buffers_size = 0;
|
_draw_buffers_size = 0;
|
||||||
glGenFramebuffers(1, &_fboId);
|
glGenFramebuffers(1, &_fboId);
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
||||||
@ -14,8 +14,7 @@ void Multipass::setDrawBuffers()
|
|||||||
{
|
{
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
||||||
glDrawBuffers(_draw_buffers_size, _draw_buffers);
|
glDrawBuffers(_draw_buffers_size, _draw_buffers);
|
||||||
int framebuffer_status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
|
if (glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE)
|
||||||
if (framebuffer_status != GL_FRAMEBUFFER_COMPLETE)
|
|
||||||
throw std::runtime_error("Error during framebuffer initialisation");
|
throw std::runtime_error("Error during framebuffer initialisation");
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
}
|
}
|
||||||
@ -36,21 +35,17 @@ Multipass::~Multipass()
|
|||||||
glDeleteFramebuffers(1, &_fboId);
|
glDeleteFramebuffers(1, &_fboId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint type, GLuint type_2, GLuint type_3,
|
void Multipass::addTexture(const std::string & tex_name, GLuint filter, GLuint type, GLuint type_2,
|
||||||
bool depth, SceneContext &scnctx, GLuint height, GLuint width)
|
bool depth, SceneContext &scnctx)
|
||||||
{
|
{
|
||||||
height = (height == 0) ? scnctx.height : height;
|
|
||||||
width = (width == 0) ? scnctx.width : width;
|
|
||||||
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
||||||
glGenTextures(1, &_pass_textures[tex_name]);;
|
glGenTextures(1, &_pass_textures[tex_name]);;
|
||||||
glBindTexture(GL_TEXTURE_2D, _pass_textures[tex_name]);
|
glBindTexture(GL_TEXTURE_2D, _pass_textures[tex_name]);
|
||||||
glTexImage2D(GL_TEXTURE_2D, 0, type, width, height, 0, type_2, type_3, 0);
|
glTexImage2D(GL_TEXTURE_2D, 0, type, scnctx.width, scnctx.height, 0, type_2, GL_FLOAT, 0);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||||
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_WRAP_T, GL_CLAMP_TO_EDGE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
if (depth)
|
if (depth)
|
||||||
{
|
{
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE, GL_COMPARE_R_TO_TEXTURE);
|
||||||
@ -66,128 +61,23 @@ void Multipass::enableFrameBufferTexture(const std::string tex_name)
|
|||||||
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
glBindFramebuffer(GL_FRAMEBUFFER, _fboId);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Multipass::gBufferSetup(SceneContext &scnctx, std::vector<std::shared_ptr<Mesh>>& meshes)
|
void Multipass::drawResultToScreen(SceneContext & scnctx)
|
||||||
{
|
|
||||||
if (shader != nullptr)
|
|
||||||
delete(shader);
|
|
||||||
shader = new Shader("textureViewer.vert", "textureViewer.frag");
|
|
||||||
shader->addUniform("tex", 0);
|
|
||||||
for (auto mesh : meshes)
|
|
||||||
mesh->shader = std::make_shared<Shader>("DSGeometryPass.vert", "DSGeometryPass.frag");
|
|
||||||
scnctx.firstRedraw = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Multipass::recomputeDeferredLights(SceneContext &scnctx)
|
|
||||||
{
|
|
||||||
if (scnctx.renderMode != DEFERRED_LIGHT)
|
|
||||||
return;
|
|
||||||
|
|
||||||
int i = 0;
|
|
||||||
for (auto light : scnctx.lights)
|
|
||||||
{
|
|
||||||
shader->addUniform("lights[" + std::to_string(i) + "].Position", glm::vec3(light.location));
|
|
||||||
shader->addUniform("lights[" + std::to_string(i) + "].Color", light.intensity);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
shader->addUniform("NLights", (int)scnctx.lights.size());
|
|
||||||
}
|
|
||||||
|
|
||||||
void Multipass::deferredLightSetup(SceneContext &scnctx, std::vector<std::shared_ptr<Mesh>>& meshes)
|
|
||||||
{
|
|
||||||
if (shader != nullptr)
|
|
||||||
delete(shader);
|
|
||||||
shader = new Shader("DSLightPass.vert", "DSLightPass.frag");
|
|
||||||
|
|
||||||
shader->addUniform("pos_tex", 0);
|
|
||||||
shader->addUniform("normal_tex", 1);
|
|
||||||
shader->addUniform("color_tex", 2);
|
|
||||||
|
|
||||||
for (auto mesh : meshes)
|
|
||||||
mesh->shader = std::make_shared<Shader>("DSGeometryPass.vert", "DSGeometryPass.frag");
|
|
||||||
|
|
||||||
recomputeDeferredLights(scnctx);
|
|
||||||
|
|
||||||
scnctx.firstRedraw = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Multipass::drawDeferredLightToScreen(SceneContext &scnctx)
|
|
||||||
{
|
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
|
||||||
glClearColor(scnctx.bg.r, scnctx.bg.g, scnctx.bg.b, scnctx.bg.a);
|
|
||||||
glViewport(0, 0, scnctx.width, scnctx.height);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _pass_textures["position_buffer"]);
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _pass_textures["normal_buffer"]);
|
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, _pass_textures["color_buffer"]);
|
|
||||||
|
|
||||||
shader->enable();
|
|
||||||
|
|
||||||
shader->addUniform("view_pos", scnctx.camPos);
|
|
||||||
|
|
||||||
glBindVertexArray(_quad_vao);
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo);
|
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glActiveTexture(GL_TEXTURE1);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glActiveTexture(GL_TEXTURE2);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
|
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
|
||||||
glBindVertexArray(0);
|
|
||||||
|
|
||||||
shader->disable();
|
|
||||||
}
|
|
||||||
|
|
||||||
void Multipass::forwardLightSetup(SceneContext &scnctx, std::vector<std::shared_ptr<Mesh>>& meshes)
|
|
||||||
{
|
|
||||||
if (shader != nullptr)
|
|
||||||
delete(shader);
|
|
||||||
shader = nullptr;
|
|
||||||
for (auto mesh : meshes)
|
|
||||||
{
|
|
||||||
mesh->shader = std::make_shared<Shader>("tex_base_light.vert", "tex_base_light.frag");
|
|
||||||
mesh->shader->addUniform("tex", 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
scnctx.firstRedraw = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
void Multipass::drawGBufferToScreen(SceneContext & scnctx)
|
|
||||||
{
|
{
|
||||||
|
//EXAMPLE CODE
|
||||||
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||||
glViewport(0, 0, scnctx.width, scnctx.height);
|
glViewport(0, 0, scnctx.width, scnctx.height);
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
shader.enable();
|
||||||
shader->enable();
|
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
glActiveTexture(GL_TEXTURE0);
|
||||||
glBindTexture(GL_TEXTURE_2D, _pass_textures[_current_tex]);
|
glBindTexture(GL_TEXTURE_2D, _pass_textures[_current_tex]);
|
||||||
|
shader.addUniform("tex", 0);
|
||||||
glBindVertexArray(_quad_vao);
|
glBindVertexArray(_quad_vao);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo);
|
glBindBuffer(GL_ARRAY_BUFFER, _quad_vbo);
|
||||||
|
|
||||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||||
|
|
||||||
glActiveTexture(GL_TEXTURE0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
glBindBuffer(GL_ARRAY_BUFFER, 0);
|
||||||
glBindVertexArray(0);
|
glBindVertexArray(0);
|
||||||
shader->disable();
|
shader.disable();
|
||||||
}
|
|
||||||
|
|
||||||
GLuint Multipass::getCurrentTexture()
|
|
||||||
{
|
|
||||||
return _pass_textures[_current_tex];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Multipass::_createQuad()
|
void Multipass::_createQuad()
|
||||||
|
|||||||
@ -3,7 +3,6 @@
|
|||||||
#include <map>
|
#include <map>
|
||||||
#include <GL/glew.h>
|
#include <GL/glew.h>
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "Models/Mesh.h"
|
|
||||||
#include "SceneContext.h"
|
#include "SceneContext.h"
|
||||||
|
|
||||||
class Multipass
|
class Multipass
|
||||||
@ -16,25 +15,13 @@ public:
|
|||||||
void setDrawBuffers();
|
void setDrawBuffers();
|
||||||
void bindToFrameBuffer(GLenum type, GLenum texture, std::string texName);
|
void bindToFrameBuffer(GLenum type, GLenum texture, std::string texName);
|
||||||
|
|
||||||
void addTexture(const std::string &tex_name, GLuint filter, GLuint type, GLuint type_2, GLuint type_3,
|
void addTexture(const std::string &tex_name, GLuint filter, GLuint type, GLuint type_2,
|
||||||
bool depth, SceneContext &scnctx, GLuint height = 0, GLuint width = 0);
|
bool depth, SceneContext &scnctx);
|
||||||
|
|
||||||
void enableFrameBufferTexture(const std::string tex_name);
|
void enableFrameBufferTexture(const std::string tex_name);
|
||||||
|
void drawResultToScreen(SceneContext &scnctx);
|
||||||
|
|
||||||
|
Shader shader;
|
||||||
void gBufferSetup(SceneContext &scnctx, std::vector<std::shared_ptr<Mesh>>& meshes);
|
|
||||||
void recomputeDeferredLights(SceneContext &scnctx);
|
|
||||||
void drawGBufferToScreen(SceneContext &scnctx);
|
|
||||||
|
|
||||||
void deferredLightSetup(SceneContext &scnctx, std::vector<std::shared_ptr<Mesh>>& meshes);
|
|
||||||
void drawDeferredLightToScreen(SceneContext &scnctx);
|
|
||||||
void forwardLightSetup(SceneContext &scnctx, std::vector<std::shared_ptr<Mesh>>& meshes);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
GLuint getCurrentTexture();
|
|
||||||
|
|
||||||
Shader *shader;
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
void _createQuad();
|
void _createQuad();
|
||||||
|
|||||||
@ -1,5 +1,4 @@
|
|||||||
#include "MyGlWindow.h"
|
#include "MyGlWindow.h"
|
||||||
|
|
||||||
//Getting the projection matrix
|
//Getting the projection matrix
|
||||||
glm::mat4x4 perspective(float fovy, float aspect, float near, float far)
|
glm::mat4x4 perspective(float fovy, float aspect, float near, float far)
|
||||||
{
|
{
|
||||||
@ -41,152 +40,20 @@ MyGlWindow::MyGlWindow(int w, int h) :
|
|||||||
m_width = w;
|
m_width = w;
|
||||||
m_height = h;
|
m_height = h;
|
||||||
|
|
||||||
scnctx.height = m_height;
|
_scnctx.height = m_height;
|
||||||
scnctx.width = m_width;
|
_scnctx.width = m_width;
|
||||||
|
|
||||||
setup();
|
setup();
|
||||||
}
|
}
|
||||||
|
|
||||||
MyGlWindow::~MyGlWindow()
|
MyGlWindow::~MyGlWindow()
|
||||||
{
|
{
|
||||||
}
|
shaders.clear();
|
||||||
|
|
||||||
void MyGlWindow::draw()
|
|
||||||
{
|
|
||||||
if (scnctx.renderMode == GBUF_DEBUG)
|
|
||||||
drawDebugGBuffer();
|
|
||||||
else if (scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
drawDeferredLight();
|
|
||||||
else if (scnctx.renderMode == FORWARD_LIGHT)
|
|
||||||
drawForwardLight();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::setBgColor(float bgColor[3])
|
void MyGlWindow::setBgColor(float bgColor[3])
|
||||||
{
|
{
|
||||||
scnctx.bg = glm::vec4(bgColor[0], bgColor[1], bgColor[2], 1);
|
_scnctx.bg = glm::vec4(bgColor[0], bgColor[1], bgColor[2], 1);
|
||||||
}
|
|
||||||
|
|
||||||
void MyGlWindow::orbitLights(float timePassed, float speed)
|
|
||||||
{
|
|
||||||
float angle = timePassed * speed;
|
|
||||||
|
|
||||||
for (auto &&light : scnctx.lights)
|
|
||||||
{
|
|
||||||
glm::mat4 rotate = glm::rotate(glm::mat4(1.0f),
|
|
||||||
glm::radians(angle), glm::vec3(0, 1, 0));
|
|
||||||
light.location = rotate * light.location;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
multipassManager.recomputeDeferredLights(scnctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyGlWindow::loadScene(SceneChoice scene)
|
|
||||||
{
|
|
||||||
meshes.clear();
|
|
||||||
scnctx.lights.clear();
|
|
||||||
|
|
||||||
float pos_x = -20;
|
|
||||||
float pos_z = -20;
|
|
||||||
Dataset moddata;
|
|
||||||
switch (scene)
|
|
||||||
{
|
|
||||||
case MOUNTAIN:
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>("mountain/mount.blend1.obj", "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
scnctx.lights.emplace_back(glm::vec3(1, 1, 1), glm::vec4(0, 2, 2, 1));
|
|
||||||
break;
|
|
||||||
case CUBES:
|
|
||||||
moddata.simpleCube();
|
|
||||||
std::srand(18);
|
|
||||||
|
|
||||||
for (int i = 1; i < 401; i++)
|
|
||||||
{
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["BrickTex"];
|
|
||||||
|
|
||||||
meshes[meshes.size() - 1]->addStartRotation(glm::vec4(1, 0, 0, 90));
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(pos_x, 0, 0, 0));
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 0, pos_z, 0));
|
|
||||||
pos_x += 2;
|
|
||||||
|
|
||||||
if (i % 20 == 0)
|
|
||||||
{
|
|
||||||
pos_x = -20;
|
|
||||||
pos_z += 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
for (int i = 0; i < 5; i++)
|
|
||||||
{
|
|
||||||
float light_r = (std::rand() % 60) / 100.f;
|
|
||||||
float light_g = (std::rand() % 60) / 100.f;
|
|
||||||
float light_b = (std::rand() % 60) / 100.f;
|
|
||||||
scnctx.lights.emplace_back(glm::vec3(light_r, light_g, light_b),
|
|
||||||
glm::vec4(std::rand() % 40 - 20, std::rand() % 3 + 3, std::rand() % 40 - 20, 1));
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case TEAPOTS:
|
|
||||||
moddata.simpleFloor();
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["BrickTex"];
|
|
||||||
meshes[meshes.size() - 1]->addStartScaling(glm::vec4(3, 1, 3, 0));
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, -1, 0, 0));
|
|
||||||
|
|
||||||
moddata.simpleCube();
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["DefaultTex"];
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(-30, 0, 0, 0));
|
|
||||||
meshes[meshes.size() - 1]->addStartScaling(glm::vec4(1, 5, 30, 0));
|
|
||||||
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["DefaultTex"];
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(30, 0, 0, 0));
|
|
||||||
meshes[meshes.size() - 1]->addStartScaling(glm::vec4(1, 5, 30, 0));
|
|
||||||
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["DefaultTex"];
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 0, 30, 0));
|
|
||||||
meshes[meshes.size() - 1]->addStartScaling(glm::vec4(30, 5, 1, 0));
|
|
||||||
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>(moddata, "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["DefaultTex"];
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(0, 0, -30, 0));
|
|
||||||
meshes[meshes.size() - 1]->addStartScaling(glm::vec4(30, 5, 1, 0));
|
|
||||||
|
|
||||||
pos_x = -30 + 4.5;
|
|
||||||
pos_z = -30 + 4.5;
|
|
||||||
|
|
||||||
for (int i = 1; i < 141; i++)
|
|
||||||
{
|
|
||||||
meshes.emplace_back(std::make_shared<Mesh>("teapot.obj", "DSGeometryPass.vert", "DSGeometryPass.frag"));
|
|
||||||
|
|
||||||
meshes[meshes.size() - 1]->textures["0"] = scnctx.textures["DefaultTex"];
|
|
||||||
meshes[meshes.size() - 1]->addStartTranslation(glm::vec4(pos_x, 0, pos_z, 0));
|
|
||||||
|
|
||||||
pos_x += 5.9;
|
|
||||||
|
|
||||||
if (i % 10 == 0)
|
|
||||||
{
|
|
||||||
pos_x = -30 + 4.5;
|
|
||||||
pos_z += 4;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (int i = 0; i < 64; i++)
|
|
||||||
{
|
|
||||||
float light_r = (std::rand() % 20) / 100.f;
|
|
||||||
float light_g = (std::rand() % 20) / 100.f;
|
|
||||||
float light_b = (std::rand() % 20) / 100.f;
|
|
||||||
scnctx.lights.emplace_back(glm::vec3(light_r, light_g, light_b),
|
|
||||||
glm::vec4(std::rand() % 60 - 30, std::rand() % 100 / 100, std::rand() % 60 - 30, 1));
|
|
||||||
}
|
|
||||||
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
this->scene = scene;
|
|
||||||
scnctx.firstRedraw = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::textureSetup()
|
void MyGlWindow::textureSetup()
|
||||||
@ -196,40 +63,96 @@ void MyGlWindow::textureSetup()
|
|||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_MIRRORED_REPEAT);
|
||||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_MIRRORED_REPEAT);
|
||||||
|
|
||||||
scnctx.textures.emplace("BrickTex", Texture("brick1.jpg"));
|
_scnctx.textures.emplace("BrickTex", Texture("brick1.jpg"));
|
||||||
scnctx.textures.emplace("MossTex", Texture("moss.png"));
|
_scnctx.textures.emplace("MossTex", Texture("moss.png"));
|
||||||
scnctx.textures.emplace("EarthTex", Texture("earth.jpg"));
|
_scnctx.textures.emplace("EarthTex", Texture("earth.jpg"));
|
||||||
scnctx.textures.emplace("DefaultTex", Texture("default.jpg"));
|
_scnctx.textures.emplace("OgreTex", Texture("Models/ogre/ogre_diffuse.png"));
|
||||||
scnctx.textures.emplace("OgreTex", Texture("Models/ogre/ogre_diffuse.png"));
|
_scnctx.textures["OgreTex"].mat.shininess = 3.0f;
|
||||||
scnctx.textures["OgreTex"].mat.shininess = 3.0f;
|
_scnctx.textures["OgreTex"].mat.ks = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||||
scnctx.textures["OgreTex"].mat.ks = glm::vec3(0.1f, 0.1f, 0.1f);
|
_scnctx.textures["OgreTex"].mat.ka = glm::vec3(0.3f, 0.3f, 0.3f);
|
||||||
scnctx.textures["OgreTex"].mat.ka = glm::vec3(0.3f, 0.3f, 0.3f);
|
_scnctx.textures["OgreTex"].mat.enabled = true;
|
||||||
scnctx.textures["OgreTex"].mat.enabled = true;
|
_scnctx.textures.emplace("OgreNmap", Texture("Models/ogre/ogre_normalmap.png"));
|
||||||
scnctx.textures.emplace("OgreNmap", Texture("Models/ogre/ogre_normalmap.png"));
|
_scnctx.textures["OgreNmap"].isNmap = true;
|
||||||
scnctx.textures["OgreNmap"].isNmap = true;
|
_scnctx.textures.emplace("CubeTex", Texture("Models/cube/color_map.jpg"));
|
||||||
scnctx.textures.emplace("CubeTex", Texture("Models/cube/color_map.jpg"));
|
_scnctx.textures["CubeTex"].mat.shininess = 3.0f;
|
||||||
scnctx.textures["CubeTex"].mat.shininess = 3.0f;
|
_scnctx.textures["CubeTex"].mat.ks = glm::vec3(0.1f, 0.1f, 0.1f);
|
||||||
scnctx.textures["CubeTex"].mat.ks = glm::vec3(0.1f, 0.1f, 0.1f);
|
_scnctx.textures["CubeTex"].mat.ka = glm::vec3(0.3f, 0.3f, 0.3f);
|
||||||
scnctx.textures["CubeTex"].mat.ka = glm::vec3(0.3f, 0.3f, 0.3f);
|
_scnctx.textures["CubeTex"].mat.enabled = true;
|
||||||
scnctx.textures["CubeTex"].mat.enabled = true;
|
_scnctx.textures.emplace("CubeNmap", Texture("Models/cube/normal_map.jpg"));
|
||||||
scnctx.textures.emplace("CubeNmap", Texture("Models/cube/normal_map.jpg"));
|
_scnctx.textures["CubeNmap"].isNmap = true;
|
||||||
scnctx.textures["CubeNmap"].isNmap = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MyGlWindow::shaderSetup()
|
||||||
|
{
|
||||||
|
shaders["Simple"] = new Shader("simple.vert", "simple.frag");
|
||||||
|
shaders["Simple"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
||||||
|
|
||||||
|
shaders["BaseLight"] = new Shader("base_light.vert", "base_light.frag");
|
||||||
|
shaders["Fog"] = new Shader("fog.vert", "fog.frag");
|
||||||
|
|
||||||
|
shaders["TexBaseLight"] = new Shader("tex_base_light.vert", "tex_base_light.frag");
|
||||||
|
shaders["TexNmapLight"] = new Shader("nmap.vert", "nmap.frag");
|
||||||
|
shaders["TexNmapLight"]->uniformFlags &= ~ShaderFlags::KD_FLAG;
|
||||||
|
|
||||||
|
shaders["SpotLight"] = new Shader("spotlight.vert", "spotlight.frag");
|
||||||
|
shaders["SpotLight"]->light_type = Light::LightType::SPOT;
|
||||||
|
shaders["TexSpotLight"] = new Shader("tex_spotlight.vert", "tex_spotlight.frag");
|
||||||
|
shaders["TexSpotLight"]->light_type = Light::LightType::SPOT;
|
||||||
|
|
||||||
|
shaders["Silhouette"] = new Shader("silhouette.vert", "silhouette.frag");
|
||||||
|
shaders["Silhouette"]->uniformFlags = ShaderFlags::MVP_FLAG;
|
||||||
|
shaders["Silhouette"]->addUniform("fColor", glm::vec3(237 / 255, 229 / 255, 194 / 255));
|
||||||
|
shaders["Silhouette"]->addUniform("sil_offset", 0.1f);
|
||||||
|
|
||||||
|
shaders["Toon"] = new Shader("base_light.vert", "toon.frag");
|
||||||
|
//Removing useless specular component
|
||||||
|
shaders["Toon"]->uniformFlags &= ~ShaderFlags::KS_FLAG;
|
||||||
|
shaders["Toon"]->uniformFlags &= ~ShaderFlags::SHINE_FLAG;
|
||||||
|
|
||||||
|
shaders["Skybox"] = new Shader("skybox.vert", "skybox.frag");
|
||||||
|
shaders["Skybox"]->uniformFlags = MVP_FLAG | MODEL_MATRIX_FLAG | SKYBOX_TEX_FLAG;
|
||||||
|
shaders["Skybox"]->addUniform("RefractionIndex", glm::vec3(0.65, 0.67, 0.69));
|
||||||
|
|
||||||
|
shaders["DSGeometryPass"] = new Shader("DSGeometryPass.vert", "DSGeometryPass.frag");
|
||||||
|
shaders["DSGeometryPass"]->uniformFlags = MVP_FLAG | KA_FLAG | KD_FLAG | KS_FLAG | SHINE_FLAG;
|
||||||
|
|
||||||
|
shaders["DSLightPass"] = new Shader("DSLightPass.vert", "DSLightPass.frag");
|
||||||
|
shaders["DSLightPass"]->uniformFlags = LIGHTS_FLAG;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyGlWindow::lightSetup()
|
||||||
|
{
|
||||||
|
//Showcase lights
|
||||||
|
_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
|
||||||
|
//_scnctx.lights.emplace("Light1", Light(glm::vec3(0.0f, 0.5f, 0.5f), glm::vec4(10, 10, 0, 1)));
|
||||||
|
//_scnctx.lights.emplace("Light2", Light(glm::vec3(0.0f, 0.0f, 0.5f), glm::vec4(3.09, 10, 9.51, 1)));
|
||||||
|
//_scnctx.lights.emplace("Light3", Light(glm::vec3(0.5f, 0.0f, 0.0f), glm::vec4(-8.09, 10, 5.87, 1)));
|
||||||
|
//_scnctx.lights.emplace("Light4", Light(glm::vec3(0.0f, 0.5f, 0.0f), glm::vec4(-8.09, 10, -5.87, 1)));
|
||||||
|
//_scnctx.lights.emplace("Light5", Light(glm::vec3(0.5f, 0.5f, 0.5f), glm::vec4(3.09, 10, -9.51, 1)));
|
||||||
|
}
|
||||||
|
|
||||||
void MyGlWindow::multipassSetup()
|
void MyGlWindow::multipassSetup()
|
||||||
{
|
{
|
||||||
multipassManager.addTexture("position_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_FLOAT, false, scnctx);
|
_multipassManager.addTexture("render_tex", GL_NEAREST, GL_RGB, GL_RGB, false, _scnctx);
|
||||||
multipassManager.addTexture("normal_buffer", GL_NEAREST, GL_RGB16F, GL_RGB, GL_UNSIGNED_BYTE, false, scnctx);
|
_multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, "render_tex");
|
||||||
multipassManager.addTexture("color_buffer", GL_NEAREST, GL_RGBA, GL_RGBA, GL_UNSIGNED_BYTE, false, scnctx);
|
|
||||||
multipassManager.addTexture("depth_tex", GL_LINEAR, GL_DEPTH_COMPONENT24, GL_DEPTH_COMPONENT, GL_FLOAT, true, scnctx);
|
|
||||||
|
|
||||||
multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, "position_buffer");
|
_multipassManager.addTexture("depth_tex", GL_LINEAR, GL_DEPTH_COMPONENT24,
|
||||||
multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT1, GL_TEXTURE_2D, "normal_buffer");
|
GL_DEPTH_COMPONENT, true, _scnctx);
|
||||||
multipassManager.bindToFrameBuffer(GL_COLOR_ATTACHMENT2, GL_TEXTURE_2D, "color_buffer");
|
_multipassManager.bindToFrameBuffer(GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, "depth_tex");
|
||||||
multipassManager.bindToFrameBuffer(GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, "depth_tex");
|
|
||||||
|
|
||||||
multipassManager.setDrawBuffers();
|
_multipassManager.setDrawBuffers();
|
||||||
|
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "depthing");
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "blurring");
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "sharpening");
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "sepia");
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "grayscale");
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "sobel_filter");
|
||||||
|
_multipassManager.shader.addSubroutine(GL_FRAGMENT_SHADER, "absolutely_no_postprocess");
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::setup()
|
void MyGlWindow::setup()
|
||||||
@ -238,114 +161,121 @@ void MyGlWindow::setup()
|
|||||||
glEnable(GL_DEPTH_BUFFER);
|
glEnable(GL_DEPTH_BUFFER);
|
||||||
glEnable(GL_TEXTURE_2D);
|
glEnable(GL_TEXTURE_2D);
|
||||||
|
|
||||||
scnctx.bg = glm::vec4(0.7, 0.7, 0.9, 1);
|
|
||||||
|
|
||||||
textureSetup();
|
textureSetup();
|
||||||
|
shaderSetup();
|
||||||
|
skybox.initialize("Models/Skybox/", shaders["Skybox"]);
|
||||||
|
skybox.scale = 10;
|
||||||
|
_scnctx.skybox_tex = skybox.getTexID();
|
||||||
|
lightSetup();
|
||||||
multipassSetup();
|
multipassSetup();
|
||||||
|
|
||||||
loadScene(TEAPOTS);
|
Dataset moddata;
|
||||||
|
moddata.checkeredFloor(100, 100, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7));
|
||||||
|
//TODO : replace by specific light shader that supports color channel (and not just materials)
|
||||||
|
meshes.emplace("Floor", new Mesh(moddata, shaders["BaseLight"]));
|
||||||
|
|
||||||
|
moddata.simpleCube();
|
||||||
|
|
||||||
|
//Hardcoded seed for easy scene replication
|
||||||
|
std::srand(18);
|
||||||
|
|
||||||
|
int zob = std::rand();
|
||||||
|
for (int i = 0; i < 100; i++)
|
||||||
|
{
|
||||||
|
std::string cube_name = "Cube" + std::to_string(i);
|
||||||
|
meshes.emplace(cube_name, new Mesh(moddata, shaders["Simple"]));
|
||||||
|
meshes[cube_name]->addStartTranslation(glm::vec4(0, 1, 0, 0));
|
||||||
|
meshes[cube_name]->addStartTranslation(glm::vec4(std::rand() % 100 - 50, 0, 0, 0));
|
||||||
|
meshes[cube_name]->addStartTranslation(glm::vec4(0, 0, std::rand() % 100 - 50, 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));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::drawDeferredLight()
|
//meshes.emplace("Ogre", new Mesh("ogre/ogre.obj", shaders["TexNmapLight"]));
|
||||||
{
|
//meshes["Ogre"]->addTranslation(glm::vec4(-0.5, 1, 0, 0));
|
||||||
if (scnctx.firstRedraw)
|
//meshes["Ogre"]->assignTexture(_scnctx.textures["OgreTex"]);
|
||||||
multipassManager.deferredLightSetup(scnctx, meshes);
|
//meshes["Ogre"]->assignTexture(_scnctx.textures["OgreNmap"]);
|
||||||
|
|
||||||
scnctx.height = m_height;
|
//meshes.emplace("Cube", new Mesh("cube/cube.obj", shaders["TexNmapLight"]));
|
||||||
scnctx.width = m_width;
|
//meshes["Cube"]->addTranslation(glm::vec4(0.5, 1, 0, 0));
|
||||||
|
//meshes["Cube"]->assignTexture(_scnctx.textures["CubeTex"]);
|
||||||
|
//meshes["Cube"]->assignTexture(_scnctx.textures["CubeNmap"]);
|
||||||
|
|
||||||
|
//meshes["Buddha"]->addScaling(glm::vec4(4, 4, 4, 0));
|
||||||
|
//meshes["Buddha"]->addRotation(glm::vec4(0, 1, 0, 180));
|
||||||
|
|
||||||
|
//meshes.emplace("Buddha", new Mesh("buddha.obj", shaders["BaseLight"]));
|
||||||
|
//meshes["Buddha"]->addTranslation(glm::vec4(-4, 3, -4, 0));
|
||||||
|
//meshes["Buddha"]->addScaling(glm::vec4(4, 4, 4, 0));
|
||||||
|
//meshes["Buddha"]->addRotation(glm::vec4(0, 1, 0, 180));
|
||||||
|
|
||||||
|
//Dataset moddata;
|
||||||
|
//moddata.simpleCube();
|
||||||
|
//meshes.emplace("Cube", new Mesh(moddata, shaders["TexBaseLight"]));
|
||||||
|
//meshes["Cube"]->assignTexture(_scnctx.textures["BrickTex"]);
|
||||||
|
//meshes["Cube"]->assignTexture(_scnctx.textures["MossTex"]);
|
||||||
|
//meshes["Cube"]->addTranslation(glm::vec4(4, 3, -4, 0));
|
||||||
|
|
||||||
|
//meshes.emplace("Mountain", new Mesh("mountain/mount.blend1.obj", shaders["TexBaseLight"]));
|
||||||
|
|
||||||
|
//meshes.emplace("Sponza", new Mesh("sponza/sponza.obj", shaders["TexBaseLight"]));
|
||||||
|
//meshes["Sponza"]->addTranslation(glm::vec4(0, -200, 0, 1));
|
||||||
|
|
||||||
|
|
||||||
|
//moddata.checkeredFloor(20, 20, glm::vec3(0.1, 0.1, 0.1), glm::vec3(0.7, 0.7, 0.7));
|
||||||
|
//meshes.emplace("Floor", new Mesh(moddata, shaders["BaseLight"]));
|
||||||
|
//meshes["Floor"]->addTranslation(glm::vec4(0, -0.05, 0, 1));
|
||||||
|
//meshes["Floor"]->cullMode = BACK;
|
||||||
|
|
||||||
|
//moddata.simpleCube();
|
||||||
|
//meshes.emplace("Cube", new Mesh(moddata, shaders["BrickBaseLight"]));
|
||||||
|
//meshes["Cube"]->addTranslation(glm::vec4(0, 1, 0, 1));
|
||||||
|
|
||||||
|
//moddata.sphere(1, 100, 100);
|
||||||
|
//meshes.emplace("Sphere", new Mesh(moddata, shaders["TexBaseLight"]));
|
||||||
|
//meshes["Sphere"]->assignTexture(_scnctx.textures["EarthTex"]);
|
||||||
|
//meshes["Sphere"]->addTranslation(glm::vec4(-5, 1, -3, 1));
|
||||||
|
|
||||||
|
//meshes.emplace("TeapotSilhouette", new Mesh("teapot.obj", shaders["Silhouette"]));
|
||||||
|
//meshes["TeapotSilhouette"]->addTranslation(glm::vec4(5, 0 ,3, 1));
|
||||||
|
//meshes["TeapotSilhouette"]->cullMode = FRONT;
|
||||||
|
//meshes.emplace("Teapot", new Mesh("teapot.obj", shaders["Toon"]));
|
||||||
|
//meshes["Teapot"]->addTranslation(glm::vec4(5, 0, 3, 1));
|
||||||
|
//meshes["Teapot"]->cullMode = BACK;
|
||||||
|
|
||||||
|
//meshes.emplace("Teapot", new Mesh("teapot.obj", shaders["Skybox"]));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void MyGlWindow::draw()
|
||||||
|
{
|
||||||
|
_scnctx.height = m_height;
|
||||||
|
_scnctx.width = m_width;
|
||||||
|
|
||||||
glm::vec3 eye(viewer.getViewPoint().x, viewer.getViewPoint().y, viewer.getViewPoint().z);
|
glm::vec3 eye(viewer.getViewPoint().x, viewer.getViewPoint().y, viewer.getViewPoint().z);
|
||||||
glm::vec3 look(viewer.getViewCenter().x, viewer.getViewCenter().y, viewer.getViewCenter().z);
|
glm::vec3 look(viewer.getViewCenter().x, viewer.getViewCenter().y, viewer.getViewCenter().z);
|
||||||
glm::vec3 up(viewer.getUpVector().x, viewer.getUpVector().y, viewer.getUpVector().z);
|
glm::vec3 up(viewer.getUpVector().x, viewer.getUpVector().y, viewer.getUpVector().z);
|
||||||
glm::mat4 view = lookAt(eye, look, up); //Calculate view matrix from parameters of m_viewer
|
glm::mat4 view = lookAt(eye, look, up); //Calculate view matrix from parameters of m_viewer
|
||||||
glm::mat4 projection = perspective(45.0f, (float)scnctx.width / (float)scnctx.height, 0.1f, 1000.0f);
|
glm::mat4 projection = perspective(45.0f, (float)_scnctx.width / (float)_scnctx.height, 0.1f, 2000.0f);
|
||||||
|
|
||||||
scnctx.camPos = eye;
|
_scnctx.viewMatrix = view;
|
||||||
scnctx.viewMatrix = view;
|
_scnctx.projectionMatrix = projection;
|
||||||
scnctx.projectionMatrix = projection;
|
|
||||||
|
|
||||||
glClearColor(scnctx.bg.r, scnctx.bg.g, scnctx.bg.b, scnctx.bg.a);
|
_multipassManager.enableFrameBufferTexture("render_tex");
|
||||||
glViewport(0, 0, scnctx.width, scnctx.height);
|
glClearColor(_scnctx.bg.r, _scnctx.bg.g, _scnctx.bg.b, _scnctx.bg.a);
|
||||||
|
glViewport(0, 0, _scnctx.width, _scnctx.height);
|
||||||
multipassManager.enableFrameBufferTexture(scnctx.fboDisplayName);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
||||||
|
|
||||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
|
||||||
(*it)->draw(scnctx);
|
|
||||||
|
|
||||||
multipassManager.drawDeferredLightToScreen(scnctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyGlWindow::drawDebugGBuffer()
|
|
||||||
{
|
|
||||||
if (scnctx.firstRedraw)
|
|
||||||
multipassManager.gBufferSetup(scnctx, meshes);
|
|
||||||
|
|
||||||
scnctx.height = m_height;
|
|
||||||
scnctx.width = m_width;
|
|
||||||
|
|
||||||
glm::vec3 eye(viewer.getViewPoint().x, viewer.getViewPoint().y, viewer.getViewPoint().z);
|
|
||||||
glm::vec3 look(viewer.getViewCenter().x, viewer.getViewCenter().y, viewer.getViewCenter().z);
|
|
||||||
glm::vec3 up(viewer.getUpVector().x, viewer.getUpVector().y, viewer.getUpVector().z);
|
|
||||||
glm::mat4 view = lookAt(eye, look, up); //Calculate view matrix from parameters of m_viewer
|
|
||||||
glm::mat4 projection = perspective(45.0f, (float)scnctx.width / (float)scnctx.height, 0.1f, 1000.0f);
|
|
||||||
|
|
||||||
scnctx.camPos = eye;
|
|
||||||
scnctx.viewMatrix = view;
|
|
||||||
scnctx.projectionMatrix = projection;
|
|
||||||
|
|
||||||
glClearColor(scnctx.bg.r, scnctx.bg.g, scnctx.bg.b, scnctx.bg.a);
|
|
||||||
glViewport(0, 0, scnctx.width, scnctx.height);
|
|
||||||
|
|
||||||
multipassManager.enableFrameBufferTexture(scnctx.fboDisplayName);
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
||||||
(*it)->draw(scnctx);
|
(*it).second->draw(_scnctx);
|
||||||
|
|
||||||
multipassManager.drawGBufferToScreen(scnctx);
|
|
||||||
|
|
||||||
|
_multipassManager.drawResultToScreen(_scnctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
void MyGlWindow::drawForwardLight()
|
|
||||||
{
|
|
||||||
if (scnctx.firstRedraw)
|
|
||||||
multipassManager.forwardLightSetup(scnctx, meshes);
|
|
||||||
|
|
||||||
scnctx.height = m_height;
|
|
||||||
scnctx.width = m_width;
|
|
||||||
|
|
||||||
glm::vec3 eye(viewer.getViewPoint().x, viewer.getViewPoint().y, viewer.getViewPoint().z);
|
|
||||||
glm::vec3 look(viewer.getViewCenter().x, viewer.getViewCenter().y, viewer.getViewCenter().z);
|
|
||||||
glm::vec3 up(viewer.getUpVector().x, viewer.getUpVector().y, viewer.getUpVector().z);
|
|
||||||
glm::mat4 view = lookAt(eye, look, up); //Calculate view matrix from parameters of m_viewer
|
|
||||||
glm::mat4 projection = perspective(45.0f, (float)scnctx.width / (float)scnctx.height, 0.1f, 1000.0f);
|
|
||||||
|
|
||||||
scnctx.camPos = eye;
|
|
||||||
scnctx.viewMatrix = view;
|
|
||||||
scnctx.projectionMatrix = projection;
|
|
||||||
|
|
||||||
glClearColor(scnctx.bg.r, scnctx.bg.g, scnctx.bg.b, scnctx.bg.a);
|
|
||||||
glViewport(0, 0, scnctx.width, scnctx.height);
|
|
||||||
|
|
||||||
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
|
|
||||||
|
|
||||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
|
||||||
{
|
|
||||||
(*it)->shader->addUniform("view_pos", scnctx.camPos);
|
|
||||||
int i = 0;
|
|
||||||
for (auto light : scnctx.lights)
|
|
||||||
{
|
|
||||||
(*it)->shader->addUniform("lights[" + std::to_string(i) + "].Position", glm::vec3(light.location));
|
|
||||||
(*it)->shader->addUniform("lights[" + std::to_string(i) + "].Color", light.intensity);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
(*it)->shader->addUniform("NLights", (int)scnctx.lights.size());
|
|
||||||
(*it)->draw(scnctx);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void MyGlWindow::resize(int w, int h)
|
void MyGlWindow::resize(int w, int h)
|
||||||
{
|
{
|
||||||
|
|||||||
@ -4,6 +4,7 @@
|
|||||||
#include "GL/glew.h"
|
#include "GL/glew.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include "Skybox.h"
|
||||||
#include "Shader.h"
|
#include "Shader.h"
|
||||||
#include "ModelView.h"
|
#include "ModelView.h"
|
||||||
#include "Viewer.h"
|
#include "Viewer.h"
|
||||||
@ -13,13 +14,6 @@
|
|||||||
#include "imgui/stb_image.h"
|
#include "imgui/stb_image.h"
|
||||||
#include "Multipass.h"
|
#include "Multipass.h"
|
||||||
|
|
||||||
enum SceneChoice
|
|
||||||
{
|
|
||||||
MOUNTAIN,
|
|
||||||
CUBES,
|
|
||||||
TEAPOTS
|
|
||||||
};
|
|
||||||
|
|
||||||
struct vertexAttr {
|
struct vertexAttr {
|
||||||
GLfloat posX, posY, posZ;
|
GLfloat posX, posY, posZ;
|
||||||
GLfloat r, g, b;
|
GLfloat r, g, b;
|
||||||
@ -32,32 +26,29 @@ public:
|
|||||||
|
|
||||||
void draw();
|
void draw();
|
||||||
void setBgColor(float bgColor[3]);
|
void setBgColor(float bgColor[3]);
|
||||||
void orbitLights(float timePassed, float speed);
|
|
||||||
void loadScene(SceneChoice scene);
|
|
||||||
|
|
||||||
std::vector<std::shared_ptr<Mesh>> meshes;
|
std::map<std::string, Shader *> shaders;
|
||||||
|
std::map<std::string, Mesh *> meshes;
|
||||||
|
|
||||||
void resize(int w, int h);
|
void resize(int w, int h);
|
||||||
Viewer viewer;
|
Viewer viewer;
|
||||||
|
|
||||||
SceneContext scnctx;
|
SceneContext _scnctx;
|
||||||
Multipass multipassManager;
|
|
||||||
SceneChoice scene;
|
|
||||||
private:
|
private:
|
||||||
int m_width;
|
int m_width;
|
||||||
int m_height;
|
int m_height;
|
||||||
|
|
||||||
float _bgColor[3];
|
float _bgColor[3];
|
||||||
|
|
||||||
|
Multipass _multipassManager;
|
||||||
|
|
||||||
|
Skybox skybox;
|
||||||
GLuint _vaoHandle;
|
GLuint _vaoHandle;
|
||||||
GLuint _iboHandle;
|
GLuint _iboHandle;
|
||||||
|
|
||||||
void drawDebugGBuffer();
|
|
||||||
void drawForwardLight();
|
|
||||||
void drawDeferredLight();
|
|
||||||
void textureSetup();
|
void textureSetup();
|
||||||
|
void shaderSetup();
|
||||||
|
void lightSetup();
|
||||||
void multipassSetup();
|
void multipassSetup();
|
||||||
void setup();
|
void setup();
|
||||||
};
|
};
|
||||||
@ -6,16 +6,9 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "Light.h"
|
#include "Light.h"
|
||||||
|
|
||||||
enum RenderMode
|
|
||||||
{
|
|
||||||
GBUF_DEBUG,
|
|
||||||
DEFERRED_LIGHT,
|
|
||||||
FORWARD_LIGHT
|
|
||||||
};
|
|
||||||
|
|
||||||
struct SceneContext
|
struct SceneContext
|
||||||
{
|
{
|
||||||
std::vector<Light> lights;
|
std::map<std::string, Light> lights;
|
||||||
std::map<std::string, float> floatValues;
|
std::map<std::string, float> floatValues;
|
||||||
|
|
||||||
glm::mat4x4 viewMatrix;
|
glm::mat4x4 viewMatrix;
|
||||||
@ -26,7 +19,7 @@ struct SceneContext
|
|||||||
glm::mat4x4 modelMatrix;
|
glm::mat4x4 modelMatrix;
|
||||||
glm::mat3x3 normalMatrix;
|
glm::mat3x3 normalMatrix;
|
||||||
|
|
||||||
GLuint skyboxTex;
|
GLuint skybox_tex;
|
||||||
|
|
||||||
std::map<std::string, Texture> textures;
|
std::map<std::string, Texture> textures;
|
||||||
|
|
||||||
@ -34,9 +27,15 @@ struct SceneContext
|
|||||||
GLuint width;
|
GLuint width;
|
||||||
glm::vec4 bg;
|
glm::vec4 bg;
|
||||||
|
|
||||||
std::string fboDisplayName;
|
void adjustSpots()
|
||||||
glm::vec3 camPos;
|
{
|
||||||
|
for (auto it : lights)
|
||||||
RenderMode renderMode;
|
{
|
||||||
bool firstRedraw;
|
if (it.second.type == Light::SPOT)
|
||||||
|
{
|
||||||
|
it.second.location = it.second.location * viewMatrix;
|
||||||
|
it.second.direction = (viewMatrix * it.second.lookAt - it.second.location * viewMatrix);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
@ -19,3 +19,75 @@ void Shader::disable()
|
|||||||
_program.disable();
|
_program.disable();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Shader::addSubroutine(GLenum shadertype, const std::string uniformName)
|
||||||
|
{
|
||||||
|
return _program.addSubroutine(shadertype, uniformName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::enableSubroutine(const std::string uniformName)
|
||||||
|
{
|
||||||
|
return _program.enableSubroutine(uniformName);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setMaterial(SceneContext ctx)
|
||||||
|
{
|
||||||
|
if ((uniformFlags & ShaderFlags::KA_FLAG) == ShaderFlags::KA_FLAG)
|
||||||
|
glUniform3fv(_program.addUniform("Ka"), 1, glm::value_ptr(mat.ka));
|
||||||
|
if ((uniformFlags & ShaderFlags::KD_FLAG) == ShaderFlags::KD_FLAG)
|
||||||
|
glUniform3fv(_program.addUniform("Kd"), 1, glm::value_ptr(mat.kd));
|
||||||
|
if ((uniformFlags & ShaderFlags::KS_FLAG) == ShaderFlags::KS_FLAG)
|
||||||
|
glUniform3fv(_program.addUniform("Ks"), 1, glm::value_ptr(mat.ks));
|
||||||
|
if ((uniformFlags & ShaderFlags::SHINE_FLAG) == ShaderFlags::SHINE_FLAG)
|
||||||
|
glUniform1f(_program.addUniform("Shininess"), mat.shininess);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setCamera(SceneContext ctx)
|
||||||
|
{
|
||||||
|
if ((uniformFlags & ShaderFlags::MVP_FLAG) == ShaderFlags::MVP_FLAG)
|
||||||
|
glUniformMatrix4fv(_program.addUniform("mvp"), 1, GL_FALSE, glm::value_ptr(ctx.mvpMatrix));
|
||||||
|
if ((uniformFlags & ShaderFlags::NORMAL_MAT_FLAG) == ShaderFlags::NORMAL_MAT_FLAG)
|
||||||
|
glUniformMatrix3fv(_program.addUniform("NormalMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.normalMatrix));
|
||||||
|
if ((uniformFlags & ShaderFlags::MODELVIEW_FLAG) == ShaderFlags::MODELVIEW_FLAG)
|
||||||
|
glUniformMatrix4fv(_program.addUniform("ModelViewMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.modelViewMatrix));
|
||||||
|
if ((uniformFlags & ShaderFlags::MODEL_MATRIX_FLAG) == ShaderFlags::MODEL_MATRIX_FLAG)
|
||||||
|
glUniformMatrix4fv(_program.addUniform("ModelMatrix"), 1, GL_FALSE, glm::value_ptr(ctx.modelMatrix));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setLights(SceneContext ctx)
|
||||||
|
{
|
||||||
|
int i = 0;
|
||||||
|
if ((uniformFlags & ShaderFlags::LIGHTS_FLAG) != ShaderFlags::LIGHTS_FLAG)
|
||||||
|
return;
|
||||||
|
for (auto light: ctx.lights)
|
||||||
|
{
|
||||||
|
if (light.second.activated && light.second.type == light_type)
|
||||||
|
{
|
||||||
|
std::string lightname = "Light[" + std::to_string(i) + "].";
|
||||||
|
|
||||||
|
glUniform4fv(_program.addUniform(lightname + "Position"), 1, glm::value_ptr(ctx.viewMatrix * light.second.location));
|
||||||
|
glUniform3fv(_program.addUniform(lightname + "Intensity"), 1, glm::value_ptr(light.second.intensity));
|
||||||
|
if (light.second.type == Light::LightType::SPOT)
|
||||||
|
{
|
||||||
|
glUniform1f(_program.addUniform(lightname + "SpotCutoff"), light.second.spot_cutoff);
|
||||||
|
glUniform1f(_program.addUniform(lightname + "SpotInnerCutoff"), light.second.spot_inner_cutoff);
|
||||||
|
glUniform1f(_program.addUniform(lightname + "SpotExponent"), light.second.spot_exponent);
|
||||||
|
glUniform3fv(_program.addUniform(lightname + "SpotDirection"), 1, glm::value_ptr(light.second.direction));
|
||||||
|
}
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
glUniform1i(_program.addUniform("LightCount"), i);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Shader::setUniforms(SceneContext ctx)
|
||||||
|
{
|
||||||
|
setCamera(ctx);
|
||||||
|
setLights(ctx);
|
||||||
|
setMaterial(ctx);
|
||||||
|
|
||||||
|
if ((uniformFlags & ShaderFlags::SKYBOX_TEX_FLAG) == ShaderFlags::SKYBOX_TEX_FLAG)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, ctx.skybox_tex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -11,6 +11,21 @@
|
|||||||
#include "Loader.h"
|
#include "Loader.h"
|
||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
|
|
||||||
|
enum ShaderFlags
|
||||||
|
{
|
||||||
|
NO_UNIFORM = 0,
|
||||||
|
KD_FLAG = 1,
|
||||||
|
KA_FLAG = 2,
|
||||||
|
KS_FLAG = 4,
|
||||||
|
SHINE_FLAG = 8,
|
||||||
|
MVP_FLAG = 16,
|
||||||
|
NORMAL_MAT_FLAG = 32,
|
||||||
|
MODELVIEW_FLAG = 64,
|
||||||
|
LIGHTS_FLAG = 128,
|
||||||
|
MODEL_MATRIX_FLAG = 256,
|
||||||
|
SKYBOX_TEX_FLAG = 512,
|
||||||
|
};
|
||||||
|
|
||||||
class Shader
|
class Shader
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -18,11 +33,16 @@ public:
|
|||||||
Shader(const std::string vtx_name, const std::string frag_name);
|
Shader(const std::string vtx_name, const std::string frag_name);
|
||||||
~Shader();
|
~Shader();
|
||||||
|
|
||||||
|
int uniformFlags = KD_FLAG | KA_FLAG | KS_FLAG | SHINE_FLAG | MVP_FLAG | NORMAL_MAT_FLAG | MODELVIEW_FLAG | LIGHTS_FLAG;
|
||||||
|
Light::LightType light_type = Light::LightType::BASE;
|
||||||
Material mat;
|
Material mat;
|
||||||
|
|
||||||
void enable();
|
void enable();
|
||||||
void disable();
|
void disable();
|
||||||
|
|
||||||
|
int addSubroutine(GLenum shadertype, const std::string uniformName);
|
||||||
|
void enableSubroutine(const std::string uniformName);
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
void setUniforms(SceneContext ctx);
|
void setUniforms(SceneContext ctx);
|
||||||
@ -42,15 +62,25 @@ public:
|
|||||||
_program.use(); glUniform1fv(_program.addUniform(name), 1, &data);
|
_program.use(); glUniform1fv(_program.addUniform(name), 1, &data);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addUniform(const std::string name, glm::mat3x3 &data)
|
|
||||||
{
|
|
||||||
_program.use(); glUniformMatrix3fv(_program.addUniform(name), 1, GL_FALSE, glm::value_ptr(data));
|
|
||||||
}
|
|
||||||
|
|
||||||
void addUniform(const std::string name, glm::mat4x4 &data)
|
void addUniform(const std::string name, glm::mat4x4 &data)
|
||||||
{
|
{
|
||||||
_program.use(); glUniformMatrix4fv(_program.addUniform(name), 1, GL_FALSE, glm::value_ptr(data));
|
_program.use(); glUniformMatrix4fv(_program.addUniform(name), 1, GL_FALSE, glm::value_ptr(data));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void applyTextureMaterial(Texture &tex)
|
||||||
|
{
|
||||||
|
if (mat.enabled)
|
||||||
|
{
|
||||||
|
addUniform("Ka", tex.mat.ka);
|
||||||
|
addUniform("Kd", tex.mat.kd);
|
||||||
|
addUniform("Ks", tex.mat.ks);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void setMaterial(SceneContext ctx);
|
||||||
|
void setCamera(SceneContext ctx);
|
||||||
|
void setLights(SceneContext ctx);
|
||||||
|
|
||||||
ShaderProgram _program;
|
ShaderProgram _program;
|
||||||
};
|
};
|
||||||
141
BaseGLProject/Skybox.cpp
Normal file
@ -0,0 +1,141 @@
|
|||||||
|
#include "Skybox.h"
|
||||||
|
#include "imgui/stb_image.h"
|
||||||
|
|
||||||
|
Skybox::Skybox()
|
||||||
|
{
|
||||||
|
float side = 50.0f; //size of cube
|
||||||
|
float side2 = side / 2.0f;
|
||||||
|
float v[24 * 3] = {
|
||||||
|
// Front
|
||||||
|
-side2, -side2, side2,
|
||||||
|
side2, -side2, side2,
|
||||||
|
side2, side2, side2,
|
||||||
|
-side2, side2, side2,
|
||||||
|
// Right
|
||||||
|
side2, -side2, side2,
|
||||||
|
side2, -side2, -side2,
|
||||||
|
side2, side2, -side2,
|
||||||
|
side2, side2, side2,
|
||||||
|
// Back
|
||||||
|
-side2, -side2, -side2,
|
||||||
|
-side2, side2, -side2,
|
||||||
|
side2, side2, -side2,
|
||||||
|
side2, -side2, -side2,
|
||||||
|
// Left
|
||||||
|
-side2, -side2, side2, //12
|
||||||
|
-side2, side2, side2, //13
|
||||||
|
-side2, side2, -side2, //14
|
||||||
|
-side2, -side2, -side2, //15
|
||||||
|
// Bottom
|
||||||
|
-side2, -side2, side2,
|
||||||
|
-side2, -side2, -side2,
|
||||||
|
side2, -side2, -side2,
|
||||||
|
side2, -side2, side2,
|
||||||
|
// Top
|
||||||
|
-side2, side2, side2,
|
||||||
|
side2, side2, side2,
|
||||||
|
side2, side2, -side2,
|
||||||
|
-side2, side2, -side2
|
||||||
|
};
|
||||||
|
|
||||||
|
GLuint el[] = {
|
||||||
|
0,2,1, 0,3,2, 4,6,5, 4,7,6,
|
||||||
|
8,10,9, 8,11,10, 12,14,13, 12,15,14,
|
||||||
|
16,18,17, 16,19,18, 20,22,21, 20,23,22
|
||||||
|
};
|
||||||
|
|
||||||
|
glGenVertexArrays(1, &vao);
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
|
||||||
|
glGenBuffers(1, &vector_vbo);
|
||||||
|
glBindBuffer(GL_ARRAY_BUFFER, vector_vbo);
|
||||||
|
glBufferData(GL_ARRAY_BUFFER, 24 * 3 * sizeof(GLfloat), v, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glVertexAttribPointer(0, 3, GL_FLOAT, GL_FALSE, sizeof(GLfloat) * 3, NULL);
|
||||||
|
glEnableVertexAttribArray(0);
|
||||||
|
|
||||||
|
glGenBuffers(1, &ibo);
|
||||||
|
glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ibo);
|
||||||
|
glBufferData(GL_ELEMENT_ARRAY_BUFFER, 36 * sizeof(GLuint), el, GL_STATIC_DRAW);
|
||||||
|
|
||||||
|
glVertexAttribPointer(4, 3, GL_FLOAT, GL_FALSE, 0, NULL);
|
||||||
|
glEnableVertexAttribArray(4);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void Skybox::initialize(std::string skybox_dir, Shader *sky)
|
||||||
|
{
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glGenTextures(1, &texID); //set the texID as a member variable
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
||||||
|
|
||||||
|
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||||
|
glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
|
||||||
|
|
||||||
|
const char * suffixes[] = { "left", "right", "top", "down", "back", "front"};
|
||||||
|
|
||||||
|
GLuint targets[] = {
|
||||||
|
GL_TEXTURE_CUBE_MAP_POSITIVE_X, GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
|
||||||
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Y, GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
|
||||||
|
GL_TEXTURE_CUBE_MAP_POSITIVE_Z, GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
|
||||||
|
};
|
||||||
|
|
||||||
|
for (int i = 0; i < 6; i++) {
|
||||||
|
int channel, width, height;
|
||||||
|
unsigned char *image;
|
||||||
|
std::string filename;
|
||||||
|
filename = std::string(skybox_dir + suffixes[i]) + std::string(".JPG");
|
||||||
|
image = stbi_load(filename.c_str(), &width, &height, &channel, 0);
|
||||||
|
glTexImage2D(targets[i], 0, GL_RGB, width, height, 0, GL_RGB, GL_UNSIGNED_BYTE, image);
|
||||||
|
glGenerateMipmap(GL_TEXTURE_2D);
|
||||||
|
stbi_image_free(image);
|
||||||
|
}
|
||||||
|
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
|
sky->enable();
|
||||||
|
sky->addUniform("DrawSkyBox", (int)GL_FALSE);
|
||||||
|
sky->addUniform("CubeMapTex", (int)0);
|
||||||
|
sky->disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
Skybox::~Skybox()
|
||||||
|
{
|
||||||
|
glDeleteBuffers(1, &vector_vbo);
|
||||||
|
glDeleteBuffers(1, &ibo);
|
||||||
|
glDeleteVertexArrays(1, &vao);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// //Things to add
|
||||||
|
// //Per model :
|
||||||
|
// // - ModelMatrix
|
||||||
|
// // - MaterialColor
|
||||||
|
|
||||||
|
void Skybox::draw(Shader *sky_shader, SceneContext &ctx)
|
||||||
|
{
|
||||||
|
sky_shader->enable();
|
||||||
|
glEnable(GL_CULL_FACE);
|
||||||
|
glCullFace(GL_BACK);
|
||||||
|
glm::mat4x4 modelMatrix = glm::scale(glm::mat4(1.0f), glm::vec3(scale));
|
||||||
|
glm::mat4x4 mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * modelMatrix;
|
||||||
|
sky_shader->addUniform("mvp", mvpMatrix);
|
||||||
|
glActiveTexture(GL_TEXTURE0);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, texID);
|
||||||
|
glBindVertexArray(vao);
|
||||||
|
sky_shader->addUniform("DrawSkyBox", (int)GL_TRUE);
|
||||||
|
|
||||||
|
|
||||||
|
int size;
|
||||||
|
glGetBufferParameteriv(GL_ELEMENT_ARRAY_BUFFER, GL_BUFFER_SIZE, &size);
|
||||||
|
glDrawElements(GL_TRIANGLES, size / sizeof(GLuint), GL_UNSIGNED_INT, 0);
|
||||||
|
|
||||||
|
sky_shader->addUniform("DrawSkyBox", (int)GL_FALSE);
|
||||||
|
glBindVertexArray(0);
|
||||||
|
glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
|
||||||
|
glDisable(GL_CULL_FACE);
|
||||||
|
sky_shader->disable();
|
||||||
|
}
|
||||||
30
BaseGLProject/Skybox.h
Normal file
@ -0,0 +1,30 @@
|
|||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <GL/glew.h>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
|
||||||
|
#include <glm/mat4x4.hpp>
|
||||||
|
#include <glm/gtc/matrix_transform.hpp>
|
||||||
|
#include <glm/gtc/matrix_inverse.hpp>
|
||||||
|
#include <glm/gtc/type_ptr.hpp>
|
||||||
|
#include "Shader.h"
|
||||||
|
#include "SceneContext.h"
|
||||||
|
|
||||||
|
class Skybox
|
||||||
|
{
|
||||||
|
private:
|
||||||
|
unsigned int vao;
|
||||||
|
unsigned int vector_vbo;
|
||||||
|
unsigned int ibo;
|
||||||
|
GLuint texID;
|
||||||
|
public:
|
||||||
|
Skybox();
|
||||||
|
float scale = 1;
|
||||||
|
void initialize(std::string skybox_dir, Shader *sky);
|
||||||
|
GLuint getTexID() { return texID; }
|
||||||
|
~Skybox();
|
||||||
|
void draw(Shader *sky_shader, SceneContext &ctx);
|
||||||
|
};
|
||||||
|
|
||||||
@ -18,8 +18,6 @@ double cx, cy;
|
|||||||
int g_width;
|
int g_width;
|
||||||
int g_height;
|
int g_height;
|
||||||
|
|
||||||
bool reset = false;
|
|
||||||
|
|
||||||
void window_size_callback(GLFWwindow* window, int width, int height)
|
void window_size_callback(GLFWwindow* window, int width, int height)
|
||||||
{
|
{
|
||||||
g_width = width;
|
g_width = width;
|
||||||
@ -30,8 +28,6 @@ static void key_callback(GLFWwindow* window, int key, int scancode, int action,
|
|||||||
{
|
{
|
||||||
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
if (key == GLFW_KEY_ESCAPE && action == GLFW_PRESS)
|
||||||
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
glfwSetWindowShouldClose(window, GLFW_TRUE);
|
||||||
if (key == GLFW_KEY_R && action == GLFW_PRESS)
|
|
||||||
reset = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
static void cursor_pos_callback(GLFWwindow* window, double xpos, double ypos)
|
||||||
@ -159,54 +155,6 @@ bool createWindow(GLFWwindow **window)
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FPSDisplay(int width)
|
|
||||||
{
|
|
||||||
static int frameCount = 0;
|
|
||||||
static int fps = 60;
|
|
||||||
static double previousTime = glfwGetTime();
|
|
||||||
double currentTime = glfwGetTime();
|
|
||||||
frameCount++;
|
|
||||||
// If a second has passed.
|
|
||||||
if (currentTime - previousTime >= 1.0)
|
|
||||||
{
|
|
||||||
fps = frameCount;
|
|
||||||
frameCount = 0;
|
|
||||||
previousTime = currentTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::Begin("FPSCounterOutline1", false,
|
|
||||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
|
||||||
ImGui::TextColored(ImVec4(0, 0, 0, 1), std::to_string(fps).c_str());
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
if (ImGui::Begin("FPSCounterOutline2", false,
|
|
||||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
|
||||||
ImGui::TextColored(ImVec4(0, 0, 0, 1), std::to_string(fps).c_str());
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
if (ImGui::Begin("FPSCounterOutline3", false,
|
|
||||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
|
||||||
ImGui::TextColored(ImVec4(0, 0, 0, 1), std::to_string(fps).c_str());
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
if (ImGui::Begin("FPSCounterOutline4", false,
|
|
||||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
|
||||||
ImGui::TextColored(ImVec4(0, 0, 0, 1), std::to_string(fps).c_str());
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
if (ImGui::Begin("FPSCounter", false,
|
|
||||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
|
||||||
ImGui::TextColored(ImVec4(1, 1, 1, 1), std::to_string(fps).c_str());
|
|
||||||
ImGui::End();
|
|
||||||
|
|
||||||
ImGui::SetWindowPos("FPSCounterOutline1", ImVec2(width - 49.f, 20.f), ImGuiCond_Once);
|
|
||||||
ImGui::SetWindowPos("FPSCounterOutline2", ImVec2(width - 51.f, 20.f), ImGuiCond_Once);
|
|
||||||
ImGui::SetWindowPos("FPSCounterOutline3", ImVec2(width - 50.f, 19.f), ImGuiCond_Once);
|
|
||||||
ImGui::SetWindowPos("FPSCounterOutline4", ImVec2(width - 50.f, 21.f), ImGuiCond_Once);
|
|
||||||
|
|
||||||
ImGui::SetWindowPos("FPSCounter", ImVec2(width - 50.f, 20.f), ImGuiCond_Once);
|
|
||||||
}
|
|
||||||
|
|
||||||
int loop(GLFWwindow *window)
|
int loop(GLFWwindow *window)
|
||||||
{
|
{
|
||||||
std::printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
|
std::printf("OpenGL %s, GLSL %s\n", glGetString(GL_VERSION), glGetString(GL_SHADING_LANGUAGE_VERSION));
|
||||||
@ -217,141 +165,56 @@ int loop(GLFWwindow *window)
|
|||||||
glfwGetWindowSize(window, &width, &heigth);
|
glfwGetWindowSize(window, &width, &heigth);
|
||||||
MyGlWindow glWin(width, heigth);
|
MyGlWindow glWin(width, heigth);
|
||||||
|
|
||||||
glWin.scnctx.fboDisplayName = "position_buffer";
|
int frameCount = 0;
|
||||||
bool is_selected = false;
|
int fps = 60;
|
||||||
|
double previousTime = glfwGetTime();
|
||||||
glWin.scnctx.renderMode = DEFERRED_LIGHT;
|
|
||||||
glWin.scnctx.firstRedraw = true;
|
|
||||||
|
|
||||||
std::vector<std::string> lights_strs;
|
|
||||||
char const **strings = nullptr;
|
|
||||||
|
|
||||||
int current_light = 0;
|
|
||||||
|
|
||||||
bool orbiting_lights = true;
|
|
||||||
float light_speed = 50.0f;
|
|
||||||
|
|
||||||
double prev_time = glfwGetTime();
|
|
||||||
double sinceLastFrame;
|
|
||||||
|
|
||||||
while (!glfwWindowShouldClose(window))
|
while (!glfwWindowShouldClose(window))
|
||||||
{
|
{
|
||||||
sinceLastFrame = glfwGetTime() - prev_time;
|
|
||||||
prev_time = glfwGetTime();
|
|
||||||
|
|
||||||
ImGui_ImplOpenGL3_NewFrame();
|
ImGui_ImplOpenGL3_NewFrame();
|
||||||
ImGui_ImplGlfw_NewFrame();
|
ImGui_ImplGlfw_NewFrame();
|
||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
if (ImGui::Begin("Scene settings"))
|
if (ImGui::Begin("First Window"))
|
||||||
{
|
{
|
||||||
if (ImGui::BeginCombo("Debug Buffer", glWin.scnctx.fboDisplayName.c_str()))
|
|
||||||
{
|
|
||||||
if (ImGui::Selectable("Position buffer", &is_selected, 0, ImVec2(120, 10)))
|
|
||||||
glWin.scnctx.fboDisplayName = "position_buffer";
|
|
||||||
if (ImGui::Selectable("Normal buffer", &is_selected, 0, ImVec2(120, 10)))
|
|
||||||
glWin.scnctx.fboDisplayName = "normal_buffer";
|
|
||||||
if (ImGui::Selectable("Color buffer", &is_selected, 0, ImVec2(120, 10)))
|
|
||||||
glWin.scnctx.fboDisplayName = "color_buffer";
|
|
||||||
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("Render Mode",
|
|
||||||
(glWin.scnctx.renderMode == DEFERRED_LIGHT) ? "Deferred Lights" : (
|
|
||||||
(glWin.scnctx.renderMode == FORWARD_LIGHT) ? "Forward Lights" : "Debug GBuffers")))
|
|
||||||
{
|
|
||||||
if (ImGui::Selectable("Draw Debug GBuffers", &is_selected, 0, ImVec2(120, 10)))
|
|
||||||
{
|
|
||||||
glWin.scnctx.renderMode = GBUF_DEBUG;
|
|
||||||
glWin.scnctx.firstRedraw = true;
|
|
||||||
}
|
|
||||||
if (ImGui::Selectable("Draw with Deferred Lights", &is_selected, 0, ImVec2(120, 10)))
|
|
||||||
{
|
|
||||||
glWin.scnctx.renderMode = DEFERRED_LIGHT;
|
|
||||||
glWin.scnctx.firstRedraw = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::Selectable("Draw with Forward Lights", &is_selected, 0, ImVec2(120, 10)))
|
|
||||||
{
|
|
||||||
glWin.scnctx.renderMode = FORWARD_LIGHT;
|
|
||||||
glWin.scnctx.firstRedraw = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (ImGui::BeginCombo("Scene Choice",
|
|
||||||
(glWin.scene == MOUNTAIN) ? "Mountain" :
|
|
||||||
(glWin.scene == CUBES) ? "Cubes" : "Teapots"))
|
|
||||||
{
|
|
||||||
if (ImGui::Selectable("Mountain", &is_selected, 0, ImVec2(100, 10)))
|
|
||||||
glWin.loadScene(SceneChoice::MOUNTAIN);
|
|
||||||
if (ImGui::Selectable("Cubes", &is_selected, 0, ImVec2(100, 10)))
|
|
||||||
glWin.loadScene(SceneChoice::CUBES);
|
|
||||||
if (ImGui::Selectable("Teapots", &is_selected, 0, ImVec2(100, 10)))
|
|
||||||
glWin.loadScene(SceneChoice::TEAPOTS);
|
|
||||||
ImGui::EndCombo();
|
|
||||||
}
|
|
||||||
|
|
||||||
ImGui::SetWindowPos(ImVec2(20, 20));
|
ImGui::SetWindowPos(ImVec2(20, 20));
|
||||||
|
|
||||||
|
static float bgColor[3] = { 0.6f, 0.6f, 0.9f };
|
||||||
|
ImGui::ColorEdit3("Background", bgColor, 0);
|
||||||
|
glWin.setBgColor(bgColor);
|
||||||
|
|
||||||
|
ImGui::SliderFloat("Light X", &(glWin._scnctx.lights["Spotlight1"].location.x), -20, 20);
|
||||||
|
ImGui::SliderFloat("Light Y", &(glWin._scnctx.lights["Spotlight1"].location.y), -20, 20);
|
||||||
|
ImGui::SliderFloat("Light Z", &(glWin._scnctx.lights["Spotlight1"].location.z), -20, 20);
|
||||||
|
ImGui::SliderFloat("Light X Intensity", &(glWin._scnctx.lights["Spotlight1"].intensity.x), 0, 1);
|
||||||
|
ImGui::SliderFloat("Light Y Intensity", &(glWin._scnctx.lights["Spotlight1"].intensity.y), 0, 1);
|
||||||
|
ImGui::SliderFloat("Light Z Intensity", &(glWin._scnctx.lights["Spotlight1"].intensity.z), 0, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
|
||||||
if (reset)
|
double currentTime = glfwGetTime();
|
||||||
|
frameCount++;
|
||||||
|
// If a second has passed.
|
||||||
|
if (currentTime - previousTime >= 1.0)
|
||||||
{
|
{
|
||||||
glWin.loadScene(SceneChoice::MOUNTAIN);
|
fps = frameCount;
|
||||||
reset = false;
|
frameCount = 0;
|
||||||
|
previousTime = currentTime;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ImGui::Begin("Light management"))
|
|
||||||
|
if (ImGui::Begin("FPSCounter", false,
|
||||||
|
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
||||||
{
|
{
|
||||||
lights_strs.clear();
|
ImGui::TextColored(ImVec4(1, 1, 0, 1), std::to_string(fps).c_str());
|
||||||
for (auto light : glWin.scnctx.lights)
|
|
||||||
lights_strs.push_back(light.toString());
|
|
||||||
|
|
||||||
std::free(strings);
|
|
||||||
strings = (char const **)std::malloc(sizeof(char *) * (lights_strs.size() + 1));
|
|
||||||
std::memset((void *)strings, 0, sizeof(char *) * (lights_strs.size() + 1));
|
|
||||||
|
|
||||||
for (int i = 0; i < lights_strs.size(); i++)
|
|
||||||
strings[i] = lights_strs[i].c_str();
|
|
||||||
|
|
||||||
ImGui::ListBox("Lights", ¤t_light, strings, lights_strs.size());
|
|
||||||
if (glWin.scnctx.lights.size() > 0)
|
|
||||||
{
|
|
||||||
if (ImGui::SliderFloat("Selected light X", &glWin.scnctx.lights[current_light].location.x, -10, 10)
|
|
||||||
&& glWin.scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
glWin.multipassManager.recomputeDeferredLights(glWin.scnctx);
|
|
||||||
if (ImGui::SliderFloat("Selected light Y", &glWin.scnctx.lights[current_light].location.y, -10, 10)
|
|
||||||
&& glWin.scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
glWin.multipassManager.recomputeDeferredLights(glWin.scnctx);
|
|
||||||
if (ImGui::SliderFloat("Selected light Z", &glWin.scnctx.lights[current_light].location.z, -10, 10)
|
|
||||||
&& glWin.scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
glWin.multipassManager.recomputeDeferredLights(glWin.scnctx);
|
|
||||||
|
|
||||||
if (ImGui::SliderFloat("Selected light R", &glWin.scnctx.lights[current_light].intensity.x, 0, 1)
|
|
||||||
&& glWin.scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
glWin.multipassManager.recomputeDeferredLights(glWin.scnctx);
|
|
||||||
if (ImGui::SliderFloat("Selected light G", &glWin.scnctx.lights[current_light].intensity.y, 0, 1)
|
|
||||||
&& glWin.scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
glWin.multipassManager.recomputeDeferredLights(glWin.scnctx);
|
|
||||||
if (ImGui::SliderFloat("Selected light B", &glWin.scnctx.lights[current_light].intensity.z, 0, 1)
|
|
||||||
&& glWin.scnctx.renderMode == DEFERRED_LIGHT)
|
|
||||||
glWin.multipassManager.recomputeDeferredLights(glWin.scnctx);
|
|
||||||
|
|
||||||
}
|
|
||||||
ImGui::Checkbox("Orbit Lights", &orbiting_lights);
|
|
||||||
ImGui::SliderFloat("Orbit degrees / second", &light_speed, 0, 360);
|
|
||||||
}
|
}
|
||||||
ImGui::End();
|
ImGui::End();
|
||||||
|
ImGui::SetWindowPos("FPSCounter", ImVec2(width - 50, 20), ImGuiCond_Once);
|
||||||
FPSDisplay(width);
|
|
||||||
|
|
||||||
glfwSwapBuffers(window);
|
glfwSwapBuffers(window);
|
||||||
glWin.draw();
|
glWin.draw();
|
||||||
if (orbiting_lights)
|
|
||||||
glWin.orbitLights(sinceLastFrame, light_speed);
|
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
ImGui_ImplOpenGL3_RenderDrawData(ImGui::GetDrawData());
|
||||||
@ -371,6 +234,9 @@ int loop(GLFWwindow *window)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// upload to padlet.com/mksung89/cameraControl2
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
GLFWwindow *win;
|
GLFWwindow *win;
|
||||||
|
|||||||
135
BaseGLProject/TextureViewer.cpp
Normal file
@ -0,0 +1,135 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
57
BaseGLProject/TextureViewer.h
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#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
|
||||||
|
|
||||||
|
Before Width: | Height: | Size: 3.1 KiB After Width: | Height: | Size: 266 B |
118
BaseGLProject/fboManager.cpp
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
#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;
|
||||||
|
}
|
||||||
|
}
|
||||||
49
BaseGLProject/fboManager.h
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
/*
|
||||||
|
* 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
|
||||||
@ -45,7 +45,7 @@ Collapsed=0
|
|||||||
|
|
||||||
[Window][First Window]
|
[Window][First Window]
|
||||||
Pos=20,20
|
Pos=20,20
|
||||||
Size=330,60
|
Size=357,188
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][FPSCounter]
|
[Window][FPSCounter]
|
||||||
@ -53,38 +53,3 @@ Pos=1030,20
|
|||||||
Size=85,32
|
Size=85,32
|
||||||
Collapsed=0
|
Collapsed=0
|
||||||
|
|
||||||
[Window][Scene settings]
|
|
||||||
Pos=20,20
|
|
||||||
Size=314,106
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][FPSCounterOutline]
|
|
||||||
Pos=1031,21
|
|
||||||
Size=32,32
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][FPSCounterOutline4]
|
|
||||||
Pos=1030,21
|
|
||||||
Size=32,32
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][FPSCounterOutline3]
|
|
||||||
Pos=1030,19
|
|
||||||
Size=32,32
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][FPSCounterOutline2]
|
|
||||||
Pos=1029,20
|
|
||||||
Size=32,32
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][FPSCounterOutline1]
|
|
||||||
Pos=1031,20
|
|
||||||
Size=32,32
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
[Window][Light management]
|
|
||||||
Pos=422,2
|
|
||||||
Size=475,163
|
|
||||||
Collapsed=0
|
|
||||||
|
|
||||||
|
|||||||
@ -1,5 +0,0 @@
|
|||||||
#version 440
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
#version 440
|
|
||||||
|
|
||||||
layout(location=0) in vec3 coord3d;
|
|
||||||
layout(location=1) in vec3 v_normal;
|
|
||||||
layout(location=2) in vec3 v_color;
|
|
||||||
layout(location=3) in vec2 v_texmap;
|
|
||||||
|
|
||||||
uniform mat4 lightmvp;
|
|
||||||
|
|
||||||
void main(void)
|
|
||||||
{
|
|
||||||
gl_Position = lightmvp * vec4(coord3d, 1.0f);
|
|
||||||
}
|
|
||||||
@ -1,69 +0,0 @@
|
|||||||
#version 440
|
|
||||||
|
|
||||||
out vec4 FragColor;
|
|
||||||
|
|
||||||
in vec2 TexCoords;
|
|
||||||
in vec3 fragPos;
|
|
||||||
in vec3 fragNormal;
|
|
||||||
in vec4 fragPosLightSpace;
|
|
||||||
|
|
||||||
uniform vec3 Kd;
|
|
||||||
uniform vec3 Ka;
|
|
||||||
uniform vec3 Ks;
|
|
||||||
uniform float Shininess;
|
|
||||||
|
|
||||||
struct LightInfo {
|
|
||||||
vec4 Position;
|
|
||||||
vec3 Intensity;
|
|
||||||
};
|
|
||||||
|
|
||||||
uniform LightInfo Light[64];
|
|
||||||
uniform int LightCount;
|
|
||||||
|
|
||||||
uniform uint hasTextureDiffuse;
|
|
||||||
uniform sampler2D tex;
|
|
||||||
uniform sampler2D depth_tex;
|
|
||||||
|
|
||||||
float ShadowCalculation(vec4 PInLightSpace)
|
|
||||||
{
|
|
||||||
// perform perspective divide
|
|
||||||
vec3 projCoords = PInLightSpace.xyz / PInLightSpace.w;
|
|
||||||
// transform to [0,1] range
|
|
||||||
projCoords = projCoords * 0.5 + 0.5; //why? because it has a values [-1, 1], convert to [0, 1]
|
|
||||||
// get closest depth value from light's perspective (using [0,1] range fragPosLight as coords)
|
|
||||||
float closestDepth = texture(depth_tex, projCoords.xy).r;
|
|
||||||
// get depth of current fragment from light's perspective
|
|
||||||
float currentDepth = projCoords.z;
|
|
||||||
// check whether current frag pos is in shadow
|
|
||||||
float bias = 0.005;
|
|
||||||
float shadow = currentDepth - bias > closestDepth ? 1.0 : 0.0;
|
|
||||||
// Supress the limit of the far / close plane
|
|
||||||
if (projCoords.z > 1.0)
|
|
||||||
shadow = 0.0;
|
|
||||||
return shadow;
|
|
||||||
}
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
//calculate diffuse, specular, ambient
|
|
||||||
|
|
||||||
vec3 c = vec3(1.0);
|
|
||||||
if (hasTextureDiffuse == 1) {
|
|
||||||
c = texture(tex, TexCoords).rgb;
|
|
||||||
}
|
|
||||||
|
|
||||||
float shadow = ShadowCalculation(fragPosLightSpace);
|
|
||||||
|
|
||||||
vec3 L = normalize(Light[LightCount - 1].Position.xyz - fragPos);
|
|
||||||
vec3 N = fragNormal;
|
|
||||||
vec3 V = normalize(-fragPos);
|
|
||||||
//vec3 R = normalize(reflect(-L, N));
|
|
||||||
vec3 H = normalize(V + L);
|
|
||||||
|
|
||||||
vec3 ambient = Ka * Light[LightCount - 1].Intensity;
|
|
||||||
vec3 diffuse = Kd * Light[LightCount - 1].Intensity * max(dot(L, N), 0.0);
|
|
||||||
vec3 specular = Ks * Light[LightCount - 1].Intensity * pow(max(dot(H, N), 0.0), Shininess);
|
|
||||||
|
|
||||||
vec3 final = (ambient + (1-shadow)*(diffuse + specular))*c;
|
|
||||||
FragColor = vec4(final,1.0);
|
|
||||||
}
|
|
||||||
@ -1,25 +0,0 @@
|
|||||||
#version 440
|
|
||||||
|
|
||||||
layout (location = 0) in vec3 position;
|
|
||||||
layout (location = 1) in vec3 normal;
|
|
||||||
layout (location = 2) in vec2 v_color;
|
|
||||||
layout (location = 3) in vec2 texCoords;
|
|
||||||
|
|
||||||
out vec2 TexCoords;
|
|
||||||
out vec3 fragPos;
|
|
||||||
out vec3 fragNormal;
|
|
||||||
out vec4 fragPosLightSpace;
|
|
||||||
|
|
||||||
uniform mat4 mvp;
|
|
||||||
uniform mat4 ModelViewMatrix;
|
|
||||||
uniform mat3 NormalMatrix;
|
|
||||||
uniform mat4 lightmvp;
|
|
||||||
|
|
||||||
void main()
|
|
||||||
{
|
|
||||||
fragNormal = normalize(NormalMatrix * normal);
|
|
||||||
fragPos = vec3(ModelViewMatrix * vec4(position,1.0));
|
|
||||||
TexCoords = texCoords;
|
|
||||||
fragPosLightSpace = lightmvp * vec4(position,1.0);
|
|
||||||
gl_Position = mvp * vec4(position, 1.0f);
|
|
||||||
}
|
|
||||||
@ -3,44 +3,57 @@
|
|||||||
in vec3 f_color;
|
in vec3 f_color;
|
||||||
out vec4 FragColors;
|
out vec4 FragColors;
|
||||||
|
|
||||||
struct Light {
|
uniform vec3 Kd;
|
||||||
vec3 Position;
|
uniform vec3 Ka;
|
||||||
vec3 Color;
|
uniform vec3 Ks;
|
||||||
|
uniform float Shininess;
|
||||||
|
|
||||||
|
struct LightInfo {
|
||||||
|
vec4 Position;
|
||||||
|
vec3 Intensity;
|
||||||
};
|
};
|
||||||
|
|
||||||
uniform Light lights[64];
|
uniform LightInfo Light[64];
|
||||||
uniform int NLights;
|
uniform int LightCount;
|
||||||
|
|
||||||
|
|
||||||
in vec3 fNormal;
|
in vec3 fNormal;
|
||||||
in vec3 pos;
|
in vec3 pos;
|
||||||
|
|
||||||
in vec2 texCoord;
|
in vec2 texCoord;
|
||||||
uniform sampler2D tex;
|
uniform int TexCount;
|
||||||
|
uniform sampler2D tex[32];
|
||||||
uniform vec3 view_pos;
|
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
|
||||||
vec3 finalColor;
|
vec3 finalColor;
|
||||||
vec3 diffuse_sum;
|
vec3 diffuse_sum;
|
||||||
vec3 specular_sum;
|
vec3 specular_sum;
|
||||||
vec3 ambient;
|
vec3 ambient;
|
||||||
|
|
||||||
vec4 texColor = texture(tex, texCoord);
|
ambient = Ka * Light[0].Intensity;
|
||||||
//Hardcoded ambient
|
for (int i=0; i<LightCount; i++)
|
||||||
ambient = texColor.rgb * 0.1;
|
|
||||||
for (int i = 0; i < NLights; i++)
|
|
||||||
{
|
{
|
||||||
vec3 L = normalize(lights[i].Position.xyz - pos);
|
vec3 L = normalize(Light[i].Position.xyz - pos);
|
||||||
vec3 N = fNormal;
|
vec3 N = fNormal;
|
||||||
vec3 V = normalize(view_pos - pos);
|
vec3 V = normalize(-pos);
|
||||||
vec3 H = normalize(V + L);
|
vec3 H = normalize(V + L);
|
||||||
|
|
||||||
vec3 diffuse = lights[i].Color * texColor.rgb * max(dot(L, N), 0.0);
|
vec3 diffuse = Kd * Light[i].Intensity * max(dot(L, N), 0.0);
|
||||||
vec3 specular = lights[i].Color * pow(max(dot(H, N), 0.0), 16.0) * 0.5;
|
vec3 specular = Ks * Light[i].Intensity * pow(max(dot(H, N), 0.0), Shininess);
|
||||||
diffuse_sum += diffuse;
|
diffuse_sum += diffuse;
|
||||||
specular_sum += specular;
|
specular_sum += specular;
|
||||||
}
|
}
|
||||||
|
|
||||||
FragColors = (vec4(ambient + diffuse_sum + specular_sum, 1));
|
vec4 texColor = texture(tex[0], texCoord);
|
||||||
|
|
||||||
|
for (int i=1; i < TexCount; i++)
|
||||||
|
{
|
||||||
|
vec4 new_tex = texture(tex[i], texCoord);
|
||||||
|
texColor = mix(new_tex, texColor, new_tex.a);
|
||||||
|
}
|
||||||
|
|
||||||
|
FragColors = (vec4(diffuse_sum + ambient, 1) * texColor + vec4(specular_sum, 1.0));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -7,7 +7,7 @@ layout(location=3) in vec2 v_texmap;
|
|||||||
|
|
||||||
uniform mat4 mvp;
|
uniform mat4 mvp;
|
||||||
uniform mat3 NormalMatrix;
|
uniform mat3 NormalMatrix;
|
||||||
uniform mat4 ModelMatrix;
|
uniform mat4 ModelViewMatrix;
|
||||||
|
|
||||||
out vec3 fNormal;
|
out vec3 fNormal;
|
||||||
out vec3 pos;
|
out vec3 pos;
|
||||||
@ -16,7 +16,9 @@ out vec2 texCoord;
|
|||||||
void main(void)
|
void main(void)
|
||||||
{
|
{
|
||||||
fNormal = normalize(NormalMatrix * v_normal);
|
fNormal = normalize(NormalMatrix * v_normal);
|
||||||
pos = (ModelMatrix * vec4(coord3d, 1.0)).xyz;
|
pos = (ModelViewMatrix * vec4(coord3d, 1.0)).xyz;
|
||||||
|
|
||||||
texCoord = v_texmap;
|
texCoord = v_texmap;
|
||||||
|
|
||||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||||
}
|
}
|
||||||
|
|||||||
101
BaseGLProject/textureManager.cpp
Normal file
@ -0,0 +1,101 @@
|
|||||||
|
|
||||||
|
|
||||||
|
#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];
|
||||||
|
}
|
||||||
41
BaseGLProject/textureManager.h
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
#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
|
||||||
@ -6,7 +6,144 @@ out vec4 final_color;
|
|||||||
|
|
||||||
uniform sampler2D tex;
|
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 = 0.1f; // zNear of your perspective projection
|
||||||
|
float zFar = 2000.0f; // zFar of your perspective projection
|
||||||
|
float depth = color.x;
|
||||||
|
float r = (2.0 * zNear) / (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);
|
||||||
|
}
|
||||||
|
|
||||||
void main()
|
void main()
|
||||||
{
|
{
|
||||||
|
//rrra because depth textures are not usual textures, they have only one channel
|
||||||
final_color = texture(tex, uv).rgba;
|
final_color = texture(tex, uv).rgba;
|
||||||
|
|
||||||
|
final_color = Shading(final_color);
|
||||||
|
|
||||||
|
// if (depth) {
|
||||||
|
// float d;
|
||||||
|
// d = LinearizeDepth(uv);
|
||||||
|
// final_color = vec4(d,d,d,1.0);
|
||||||
|
// }
|
||||||
|
// else if (blur)
|
||||||
|
// {
|
||||||
|
// final_color = vec4(blurring_func(uv), 1);
|
||||||
|
// }
|
||||||
|
// else if (sharpen)
|
||||||
|
// {
|
||||||
|
// final_color = vec4(sharpening_func(uv));
|
||||||
|
// }
|
||||||
|
// else if (sepia)
|
||||||
|
// {
|
||||||
|
// final_color = vec4(final_color.r * .393 + final_color.g * .769 + final_color.b * .189,
|
||||||
|
// final_color.r * .349 + final_color.g * .686 + final_color.b * .168,
|
||||||
|
// final_color.r * .272 + final_color.g * .534 + final_color.b * .131, 1.0);
|
||||||
|
// }
|
||||||
|
// else if (grayscale)
|
||||||
|
// {
|
||||||
|
// float average = final_color.r * 0.2126 + final_color.g * 0.7152 + final_color.b * 0.0722;
|
||||||
|
// final_color = vec4(average, average, average, 1.0);
|
||||||
|
// }
|
||||||
|
// else if (sobel)
|
||||||
|
// {
|
||||||
|
// vec3 sobeled = sobel_filter(final_color.rgb);
|
||||||
|
// float average = sobeled.r * 0.2126 + sobeled.g * 0.7152 + sobeled.b * 0.0722;
|
||||||
|
// final_color = vec4(average, average, average, 1.0);
|
||||||
|
// }
|
||||||
}
|
}
|
||||||