Skip to content

Commit

Permalink
GPU Selection and Alpha Clipping
Browse files Browse the repository at this point in the history
  • Loading branch information
ojaskavathe committed Nov 27, 2022
1 parent 166458a commit 1cddadd
Show file tree
Hide file tree
Showing 6 changed files with 105 additions and 17 deletions.
4 changes: 2 additions & 2 deletions openGL/imgui.ini
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ Size=339,48
Collapsed=0

[Window][Model]
Pos=395,87
Pos=439,15
Size=348,222
Collapsed=0
Collapsed=1

6 changes: 5 additions & 1 deletion openGL/res/shaders/PBR/PBR_Modelf.frag
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,11 @@ float roughness = roughnessVal;

void main()
{
if ( hasAlbedoTex ) albedo = vec3(texture(albedoTex, TexCoords).rgb);
if ( hasAlbedoTex )
{
albedo = vec3(texture(albedoTex, TexCoords).rgb);
if(texture(albedoTex, TexCoords).a < 0.01) discard; //clip transparent backgrounds
}

if ( hasMetRoughTex ) {
metallic = texture(metallicRoughnessTex, TexCoords).b * metallicVal;
Expand Down
9 changes: 9 additions & 0 deletions openGL/src/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
#include "tests/Test_Compute.h"
#include <GLFW\glfw3.h>

#include <windows.h> // for nvidia optimus

void framebuffer_size_callback(GLFWwindow* window, int width, int height);
void mouse_callback(GLFWwindow* window, double xPos, double yPos);
void scroll_callback(GLFWwindow* window, double xOffset, double yOffset);
Expand All @@ -20,6 +22,11 @@ test::Test* mTest;
float deltaTime = 0.0f;
float LastFrame = 0.0f;

extern "C" {
_declspec(dllexport) DWORD NvOptimusEnablement = 1;
_declspec(dllexport) int AmdPowerXpressRequestHighPerformance = 1;
}

int main()
{
glfwInit();
Expand Down Expand Up @@ -71,6 +78,8 @@ int main()
//https://developer.nvidia.com/content/depth-precision-visualized
glClipControl(GL_LOWER_LEFT, GL_ZERO_TO_ONE); //set up for depth precision control

std::cout << glGetString(GL_RENDERER) << "\n";

while (!glfwWindowShouldClose(window))
{
//setDeltaTime
Expand Down
10 changes: 5 additions & 5 deletions openGL/src/loaders/GLTFLoader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,20 +164,20 @@ void GLTFLoader::traverseNode(const unsigned int& nextNode, const glm::mat4& mat

if (node["children"].is_array()) {
//SUPER SKETCH PLSSSS FIX
std::cout << m_CurrIndent;
//std::cout << m_CurrIndent;
m_CurrIndent += " ";
std::string name = node["name"];
std::cout << name << "\n";
//std::cout << name << "\n";
for (unsigned int i = 0; i < node["children"].size(); ++i) {
unsigned int childNum = node["children"][i];
if (!(JSON["nodes"][childNum]["children"].is_array())) {
/*if (!(JSON["nodes"][childNum]["children"].is_array())) {
std::string childName = JSON["nodes"][childNum]["name"];
std::cout << m_CurrIndent;
std::cout << childName << "\n";
}
}*/
traverseNode(node["children"][i], matNextNode);
}
m_CurrIndent.erase(std::remove(m_CurrIndent.end() - 8, m_CurrIndent.end(), ' '), m_CurrIndent.end());
//m_CurrIndent.erase(std::remove(m_CurrIndent.end() - 8, m_CurrIndent.end(), ' '), m_CurrIndent.end());
}
/*else if (JSON["nodes"][(signed int)nextNode - 1].is_object()) {
isChild = false;
Expand Down
86 changes: 81 additions & 5 deletions openGL/src/tests/Test_Compute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,7 @@ test::Test_Compute::Test_Compute()
quadVB.Delete();
planeVB.Delete();

lightPos.emplace_back(glm::vec4(1.f, 1.0f, 1.4f, 1.f));
lightPos.emplace_back(glm::vec4(-1.f, 1.0f, 1.4f, 1.f));
lightPos.emplace_back(glm::vec4(-3.f, 3.0f, -0.2f, 1.f));

//SSBO
glGenBuffers(1, &lightPosSSBO);
Expand Down Expand Up @@ -303,6 +302,33 @@ void test::Test_Compute::OnRender()
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//red one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-3.f, 1.0f, -0.8f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
depthMapShader.SetUniformMatrix4fv("model", model);
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//blue one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-3.f, 1.0f, 0.2f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
depthMapShader.SetUniformMatrix4fv("model", model);
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//green one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-4.f, 1.0f, -0.3f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
depthMapShader.SetUniformMatrix4fv("model", model);
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//Framebuffer: Omni Shadowmap
glViewport(0, 0, SHADOW_WIDTH, SHADOW_HEIGHT);
glBindFramebuffer(GL_FRAMEBUFFER, oDepthMapFB);
Expand Down Expand Up @@ -335,8 +361,27 @@ void test::Test_Compute::OnRender()
glDrawArrays(GL_TRIANGLES, 0, 6);

//transparent cube
//red one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, 2.0));
model = glm::translate(model, glm::vec3(-3.f, 1.0f, -0.8f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
omniDepthShader.SetUniformMatrix4fv("model", model);
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//blue one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-3.f, 1.0f, 0.2f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
omniDepthShader.SetUniformMatrix4fv("model", model);
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//green one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-4.f, 1.0f, -0.3f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
omniDepthShader.SetUniformMatrix4fv("model", model);
Expand Down Expand Up @@ -500,14 +545,15 @@ void test::Test_Compute::OnRender()
experimental.SetUniform3fv("dirLight.color", dirLightColor);

experimental.SetUniform3fv("pointLight.color", pointLightColor);
experimental.SetUniform3fv("pointLight.position", pointLightPosition);
experimental.SetUniform3fv("pointLight.position", lightPos[0]);

experimental.SetUniform1f("mat.shininess", matShininess);

glDisable(GL_CULL_FACE); //<-disable face culling for transparent rendering

//red one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-1.0f, 0.0f, 2.0));
model = glm::translate(model, glm::vec3(-3.f, 1.0f, -0.8f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
experimental.SetUniformMatrix4fv("model", model);
Expand All @@ -520,6 +566,36 @@ void test::Test_Compute::OnRender()
va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//blue one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-3.f, 1.0f, 0.2f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
experimental.SetUniformMatrix4fv("model", model);
mvp = projection * view * model;
experimental.SetUniformMatrix4fv("mvp", mvp);
normal = glm::transpose(glm::inverse(model));
experimental.SetUniformMatrix4fv("normalMatrix", normal);
experimental.SetUniform4fv("color", glm::vec4(0.0f, 0.0f, 1.0f, 0.3f));

va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

//green one
model = glm::mat4(1.0f);
model = glm::translate(model, glm::vec3(-4.f, 1.0f, -0.3f));
model = glm::rotate(model, glm::radians(60.0f), glm::normalize(glm::vec3(1.0, 0.0, 1.0)));
model = glm::scale(model, glm::vec3(0.25));
experimental.SetUniformMatrix4fv("model", model);
mvp = projection * view * model;
experimental.SetUniformMatrix4fv("mvp", mvp);
normal = glm::transpose(glm::inverse(model));
experimental.SetUniformMatrix4fv("normalMatrix", normal);
experimental.SetUniform4fv("color", glm::vec4(0.0f, 1.0f, 0.0f, 0.3f));

va.Bind();
glDrawArrays(GL_TRIANGLES, 0, 36);

glBindFramebuffer(GL_READ_FRAMEBUFFER, transparentFB.getID());
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, transparentScreenFB.getID());

Expand Down
7 changes: 3 additions & 4 deletions openGL/src/tests/Test_Compute.h
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ namespace test {
void CursorInput(double xPos, double yPos) override;
void ScrollInput(double xOffset, double yOffset) override;

Camera cam;
Camera cam = Camera(glm::vec3(2, 2, 0), glm::vec3(0, 1, 0), 180.f);

private:

Expand Down Expand Up @@ -179,7 +179,6 @@ namespace test {

unsigned int lightPosSSBO;
std::vector<glm::vec4> lightPos;
glm::vec3 pointLightPosition = glm::vec3(1.2f, 3.0f, 2.0f);

glm::vec3 pointLightColor = glm::vec3(10.f);
glm::vec3 pointLightAmbient = glm::vec3(0.2f);
Expand Down Expand Up @@ -216,8 +215,8 @@ namespace test {
int swtch = 0;
float lod = 0.f;
int mapped = 0;
float iblIntensity = 1.f;
float iblIntensity = 0.02f;

Model mdl = Load::GLTF("res/models/glaive/glaive.gltf");
Model mdl = Load::GLTF("res/models/Sponza/Sponza.gltf");
};
}

0 comments on commit 1cddadd

Please sign in to comment.