Merge branch 'DeferredShading'
This commit is contained in:
commit
41798d428a
@ -194,6 +194,10 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="base_light.frag" />
|
||||
<None Include="DSGeometryPass.frag" />
|
||||
<None Include="DSGeometryPass.vert" />
|
||||
<None Include="DSLightPass.frag" />
|
||||
<None Include="DSLightPass.vert" />
|
||||
<None Include="fog.frag" />
|
||||
<None Include="fog.vert" />
|
||||
<None Include="base_light.vert" />
|
||||
|
||||
@ -223,16 +223,16 @@
|
||||
<None Include="textureViewer.frag">
|
||||
<Filter>MankyuCode</Filter>
|
||||
</None>
|
||||
<None Include="shadow_light.vert">
|
||||
<None Include="DSGeometryPass.vert">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="shadow_light.frag">
|
||||
<None Include="DSGeometryPass.frag">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="light_pov.vert">
|
||||
<None Include="DSLightPass.vert">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
<None Include="light_pov.frag">
|
||||
<None Include="DSLightPass.frag">
|
||||
<Filter>Shaders</Filter>
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
10
BaseGLProject/DSGeometryPass.frag
Normal file
10
BaseGLProject/DSGeometryPass.frag
Normal file
@ -0,0 +1,10 @@
|
||||
#version 440
|
||||
//Copy of simple.frag
|
||||
|
||||
in vec3 f_color;
|
||||
out vec4 FragColors;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColors = vec4(f_color, 1.f);
|
||||
}
|
||||
18
BaseGLProject/DSGeometryPass.vert
Normal file
18
BaseGLProject/DSGeometryPass.vert
Normal file
@ -0,0 +1,18 @@
|
||||
#version 440
|
||||
// Copy of simple.vert
|
||||
|
||||
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;
|
||||
|
||||
|
||||
out vec3 f_color;
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
f_color = v_color;
|
||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||
}
|
||||
10
BaseGLProject/DSLightPass.frag
Normal file
10
BaseGLProject/DSLightPass.frag
Normal file
@ -0,0 +1,10 @@
|
||||
#version 440
|
||||
//Copy of simple.frag
|
||||
|
||||
in vec3 f_color;
|
||||
out vec4 FragColors;
|
||||
|
||||
void main()
|
||||
{
|
||||
FragColors = vec4(f_color, 1.f);
|
||||
}
|
||||
18
BaseGLProject/DSLightPass.vert
Normal file
18
BaseGLProject/DSLightPass.vert
Normal file
@ -0,0 +1,18 @@
|
||||
#version 440
|
||||
// Copy of simple.vert
|
||||
|
||||
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;
|
||||
|
||||
|
||||
out vec3 f_color;
|
||||
|
||||
uniform mat4 mvp;
|
||||
|
||||
void main(void)
|
||||
{
|
||||
f_color = v_color;
|
||||
gl_Position = mvp * vec4(coord3d, 1.0f);
|
||||
}
|
||||
@ -476,9 +476,12 @@ void Mesh::draw(SceneContext &ctx) {
|
||||
|
||||
// Setting the space matrixes uniques to the object
|
||||
ctx.modelMatrix = model.getMatrix();
|
||||
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
||||
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
||||
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix)));
|
||||
if (shader->uniformFlags & MVP_FLAG)
|
||||
ctx.mvpMatrix = ctx.projectionMatrix * ctx.viewMatrix * ctx.modelMatrix;
|
||||
if (shader->uniformFlags & MODELVIEW_FLAG)
|
||||
ctx.modelViewMatrix = ctx.viewMatrix * ctx.modelMatrix;
|
||||
if (shader->uniformFlags & NORMAL_MAT_FLAG)
|
||||
ctx.normalMatrix = glm::mat3(glm::transpose(glm::inverse(ctx.modelViewMatrix)));
|
||||
|
||||
//Sending the uniform data to the shader
|
||||
|
||||
@ -516,6 +519,21 @@ void Mesh::effectTransformations()
|
||||
}
|
||||
}
|
||||
|
||||
void Mesh::addStartRotation(glm::vec4 vec)
|
||||
{
|
||||
model.glRotate(vec.w, vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
void Mesh::addStartTranslation(glm::vec4 vec)
|
||||
{
|
||||
model.glTranslate(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
void Mesh::addStartScaling(glm::vec4 vec)
|
||||
{
|
||||
model.glScale(vec.x, vec.y, vec.z);
|
||||
}
|
||||
|
||||
void Mesh::addRotation(glm::vec4 vec)
|
||||
{
|
||||
_transformations.emplace_back(vec, Rotation);
|
||||
|
||||
@ -88,6 +88,11 @@ public:
|
||||
void addRotation(glm::vec4 vec);
|
||||
void addTranslation(glm::vec4 vec);
|
||||
void addScaling(glm::vec4 vec);
|
||||
|
||||
void addStartRotation(glm::vec4 vec);
|
||||
void addStartTranslation(glm::vec4 vec);
|
||||
void addStartScaling(glm::vec4 vec);
|
||||
|
||||
glm::vec4 translateToPivot(glm::vec3);
|
||||
void removeLastTransformations(int n);
|
||||
glm::vec3 getPosition();
|
||||
|
||||
@ -116,6 +116,12 @@ void MyGlWindow::shaderSetup()
|
||||
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()
|
||||
@ -144,13 +150,13 @@ void MyGlWindow::multipassSetup()
|
||||
|
||||
_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, "no_postprocess");
|
||||
_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()
|
||||
@ -166,6 +172,30 @@ void MyGlWindow::setup()
|
||||
_scnctx.skybox_tex = skybox.getTexID();
|
||||
lightSetup();
|
||||
multipassSetup();
|
||||
|
||||
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));
|
||||
|
||||
}
|
||||
|
||||
//meshes.emplace("Ogre", new Mesh("ogre/ogre.obj", shaders["TexNmapLight"]));
|
||||
//meshes["Ogre"]->addTranslation(glm::vec4(-0.5, 1, 0, 0));
|
||||
@ -248,26 +278,12 @@ void MyGlWindow::draw()
|
||||
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);
|
||||
|
||||
//shaders["Skybox"]->addUniform("WorldCamPos", eye);
|
||||
|
||||
|
||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
||||
(*it).second->draw(_scnctx);
|
||||
|
||||
GLuint depth_tex = _multipassManager.getCurrentTexture();
|
||||
/*_multipassManager.enableFrameBufferTexture("render_tex");
|
||||
|
||||
for (auto it = meshes.begin(); it != meshes.end(); it++)
|
||||
{
|
||||
(*it).second->shader = shaders["ShadowLight"];
|
||||
(*it).second->shader->addUniform("lightmvp", lightMVP);
|
||||
(*it).second->shader->addUniform("depth_tex", (int)depth_tex);
|
||||
(*it).second->draw(_scnctx);
|
||||
}*/
|
||||
|
||||
_multipassManager.shader->enableSubroutine("depthing");
|
||||
_multipassManager.drawResultToScreen(_scnctx);
|
||||
//skybox.draw(shaders["Skybox"], _scnctx);
|
||||
|
||||
_multipassManager.drawResultToScreen(_scnctx);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -165,6 +165,10 @@ int loop(GLFWwindow *window)
|
||||
glfwGetWindowSize(window, &width, &heigth);
|
||||
MyGlWindow glWin(width, heigth);
|
||||
|
||||
int frameCount = 0;
|
||||
int fps = 60;
|
||||
double previousTime = glfwGetTime();
|
||||
|
||||
while (!glfwWindowShouldClose(window))
|
||||
{
|
||||
ImGui_ImplOpenGL3_NewFrame();
|
||||
@ -188,7 +192,27 @@ int loop(GLFWwindow *window)
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
|
||||
double currentTime = glfwGetTime();
|
||||
frameCount++;
|
||||
// If a second has passed.
|
||||
if (currentTime - previousTime >= 1.0)
|
||||
{
|
||||
fps = frameCount;
|
||||
frameCount = 0;
|
||||
previousTime = currentTime;
|
||||
}
|
||||
|
||||
|
||||
if (ImGui::Begin("FPSCounter", false,
|
||||
ImGuiWindowFlags_NoBackground | ImGuiWindowFlags_NoDecoration | ImGuiWindowFlags_NoFocusOnAppearing))
|
||||
{
|
||||
ImGui::TextColored(ImVec4(1, 1, 0, 1), std::to_string(fps).c_str());
|
||||
|
||||
}
|
||||
ImGui::End();
|
||||
ImGui::SetWindowPos("FPSCounter", ImVec2(width - 50, 20), ImGuiCond_Once);
|
||||
|
||||
glfwSwapBuffers(window);
|
||||
glWin.draw();
|
||||
|
||||
|
||||
@ -48,3 +48,8 @@ Pos=20,20
|
||||
Size=357,188
|
||||
Collapsed=0
|
||||
|
||||
[Window][FPSCounter]
|
||||
Pos=1030,20
|
||||
Size=85,32
|
||||
Collapsed=0
|
||||
|
||||
|
||||
@ -17,6 +17,12 @@ vec2 offsets[9] = vec2[](
|
||||
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)
|
||||
{
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user