summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Park <SebPark03@gmail.com>2024-05-09 23:18:46 -0400
committerSebastian Park <SebPark03@gmail.com>2024-05-09 23:18:46 -0400
commitf9819ae7f8b11b298c16eb14d929a9c09038a877 (patch)
treecef7f0c104d49d41a1e2c76bec2343f875ca8dff
parentac3f1e423e696392ea0a50c2652b829e5c5734b6 (diff)
parent99c588d4da2ca044df8276b7efbd9d27c19c8352 (diff)
Merge branch 'shaders'
-rw-r--r--CMakeLists.txt4
-rw-r--r--CMakeLists.txt.user24
-rw-r--r--resources/shaders/caustics.frag20
-rw-r--r--resources/shaders/caustics.vert53
-rw-r--r--resources/shaders/color.frag15
-rw-r--r--resources/shaders/color.vert3
-rwxr-xr-xresources/shaders/shader.frag1
-rw-r--r--src/arap.cpp123
-rw-r--r--src/arap.h8
-rwxr-xr-xsrc/glwidget.cpp60
-rwxr-xr-xsrc/glwidget.h7
11 files changed, 246 insertions, 72 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 402d6ec..b72cde6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -37,6 +37,7 @@ add_executable(${PROJECT_NAME}
src/graphics/meshloader.cpp
src/graphics/shader.cpp
src/graphics/shape.cpp
+# src/graphics/simpleshape.cpp
# src/graphics/oceanshape.cpp
src/mainwindow.h
@@ -47,6 +48,7 @@ add_executable(${PROJECT_NAME}
src/graphics/meshloader.h
src/graphics/shader.h
src/graphics/shape.h
+# src/graphics/simpleshape.h
# src/graphics/oceanshape.h
util/tiny_obj_loader.h
@@ -127,6 +129,8 @@ qt6_add_resources(${PROJECT_NAME} "Resources"
resources/images/foam3.png
+ resources/shaders/caustics.vert
+ resources/shaders/caustics.frag
)
# GLEW: this provides support for Windows (including 64-bit)
diff --git a/CMakeLists.txt.user b/CMakeLists.txt.user
index 077c2df..b8e5e0a 100644
--- a/CMakeLists.txt.user
+++ b/CMakeLists.txt.user
@@ -1,14 +1,10 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE QtCreatorProject>
-<<<<<<< HEAD
-<!-- Written by QtCreator 8.0.1, 2024-05-07T03:41:57. -->
-=======
-<!-- Written by QtCreator 8.0.1, 2024-05-07T05:26:10. -->
->>>>>>> let-em-cook
+<!-- Written by QtCreator 8.0.1, 2024-05-09T03:00:17. -->
<qtcreator>
<data>
<variable>EnvironmentId</variable>
- <value type="QByteArray">{543a715d-8664-4ae3-b37a-5c03b38d6a62}</value>
+ <value type="QByteArray">{96b0a71f-92bf-4ce4-971d-9106997a27d2}</value>
</data>
<data>
<variable>ProjectExplorer.Project.ActiveTarget</variable>
@@ -84,6 +80,9 @@
<valuelist type="QVariantList" key="ClangTools.SuppressedDiagnostics"/>
<value type="bool" key="ClangTools.UseGlobalSettings">true</value>
</valuemap>
+ <valuemap type="QVariantMap" key="CppEditor.QuickFix">
+ <value type="bool" key="UseGlobalSettings">true</value>
+ </valuemap>
</valuemap>
</data>
<data>
@@ -108,7 +107,7 @@
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value>
<value type="int" key="EnableQmlDebugging">0</value>
- <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Debug</value>
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Debug</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
@@ -156,7 +155,7 @@
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value>
- <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value>
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
@@ -204,7 +203,7 @@
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value>
- <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-RelWithDebInfo</value>
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-RelWithDebInfo</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
@@ -251,7 +250,7 @@
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value>
<value type="int" key="EnableQmlDebugging">0</value>
- <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Profile</value>
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Profile</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
@@ -297,7 +296,7 @@
-DCMAKE_CXX_COMPILER:FILEPATH=%{Compiler:Executable:Cxx}
-DCMAKE_CXX_FLAGS_INIT:STRING=%{Qt:QML_DEBUG_FLAG}
%{CMAKE_OSX_ARCHITECTURES:DefaultFlag}</value>
- <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-MinSizeRel</value>
+ <value type="QString" key="ProjectExplorer.BuildConfiguration.BuildDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-MinSizeRel</value>
<valuemap type="QVariantMap" key="ProjectExplorer.BuildConfiguration.BuildStepList.0">
<valuemap type="QVariantMap" key="ProjectExplorer.BuildStepList.Step.0">
<valuelist type="QVariantList" key="CMakeProjectManager.MakeStep.BuildTargets">
@@ -361,7 +360,8 @@
<value type="bool" key="RunConfiguration.UseLibrarySearchPath">true</value>
<value type="bool" key="RunConfiguration.UseQmlDebugger">false</value>
<value type="bool" key="RunConfiguration.UseQmlDebuggerAuto">true</value>
- <value type="QString" key="RunConfiguration.WorkingDirectory.default">/Users/jesswan/Desktop/cs2240/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value>
+ <value type="QString" key="RunConfiguration.WorkingDirectory">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/</value>
+ <value type="QString" key="RunConfiguration.WorkingDirectory.default">/Users/sebastianpark/College/2023-24/CSCI_2240/ocean-simulation/build/build-ocean-simulation-Qt_6_2_4_for_macOS-Release</value>
</valuemap>
<value type="qlonglong" key="ProjectExplorer.Target.RunConfigurationCount">1</value>
</valuemap>
diff --git a/resources/shaders/caustics.frag b/resources/shaders/caustics.frag
new file mode 100644
index 0000000..f746896
--- /dev/null
+++ b/resources/shaders/caustics.frag
@@ -0,0 +1,20 @@
+#version 410 core
+out vec4 fragColor;
+
+in vec3 normal_worldSpace;
+in vec3 pos;
+in vec3 newPos;
+in vec4 col;
+in float refractProb;
+
+uniform sampler2D normSamp;
+
+void main() {
+// fragColor = vec4(vec3((pos[0] + 1) / 2, (pos[1] + 1) / 2, 0.f), 1.f);
+ float oldArea = length(dFdx(vec3(pos[0], pos[2], pos[1]))) * length(dFdy(vec3(pos[0], pos[2], pos[1])));
+ float newArea = length(dFdx(vec3(newPos[0], newPos[2], newPos[1]))) * length(dFdy(vec3(newPos[0], newPos[2], newPos[1])));
+ float areaRatio = oldArea / newArea;
+ float intensity = pow(areaRatio * .3f, 1.5f);
+ fragColor = vec4(0.98, 1, .78, intensity * refractProb);
+// fragColor = col;
+}
diff --git a/resources/shaders/caustics.vert b/resources/shaders/caustics.vert
new file mode 100644
index 0000000..298f5e1
--- /dev/null
+++ b/resources/shaders/caustics.vert
@@ -0,0 +1,53 @@
+#version 330 core
+
+layout(location = 0) in vec3 position; // Position of the vertex
+layout(location = 1) in vec3 normal; // Normal of the vertex
+layout(location = 2) in vec3 texCoords; // Normal of the vertex
+
+uniform float depth = -1000.f;
+uniform float skyHeight = 500.f;
+
+uniform sampler2D normSamp;
+
+out vec3 normal_worldSpace;
+out vec3 pos;
+out vec3 newPos;
+out vec4 col;
+out float refractProb;
+
+vec4 refractToFloor(vec3 l, vec3 p, vec3 n, float d) {
+ // Refracts incoming light direction l through normal n at point p until hits floor at depth d
+ vec3 w_o = normalize(l);
+ float cos_theta_i = dot(-w_o, n);
+ float n_i = 1;
+ float n_t = 1.33f;
+ float determinant = 1.f - (pow((n_i / n_t), 2.f) * (1.f - pow(cos_theta_i, 2.f)));
+
+ float r0 = pow((n_i - n_t) / (n_i + n_t), 2.f); // variable required to calculate probability of reflection
+ float prob_to_refl = r0 + ((1 - r0) * pow((1 - cos_theta_i), 5.f));
+
+ if (determinant >= 0) {
+ float cos_theta_t = sqrt(determinant);
+ vec3 w_t = (n_i / n_t) * w_o + ((n_i / n_t) * cos_theta_i - cos_theta_t) * n;
+ float dist = p.z - d;
+ float depthScale = dist / w_t.z;
+// vec3 groundContactPoint = -(w_t * depthScale) + p;
+ vec3 groundContactPoint = (w_t * depthScale) + p;
+ return vec4(groundContactPoint, 1.f - prob_to_refl);
+ } else {
+ return vec4(0, 0, 0, 0);
+ }
+}
+
+void main() {
+ normal_worldSpace = normal;
+ pos = position;
+ vec4 sampledNormal = texture(normSamp, vec2((pos + 1) / 2));
+ sampledNormal = (sampledNormal * 2.f) - 1.f;
+ col = sampledNormal;
+ vec4 newPosAndProb = refractToFloor(vec3(0, 0, 1), pos, normalize(vec3(sampledNormal)), 0.01f);
+ newPos = vec3(newPosAndProb[0], newPosAndProb[1], 0.f);
+ refractProb = newPosAndProb[3];
+// newPos = pos;
+ gl_Position = vec4(newPos, 1.f);
+}
diff --git a/resources/shaders/color.frag b/resources/shaders/color.frag
index fe70983..7c41c89 100644
--- a/resources/shaders/color.frag
+++ b/resources/shaders/color.frag
@@ -13,16 +13,16 @@ in float intensity;
//uniform float intExp = 0.5f;
//uniform float scale = 1.f;
-uniform float multiplier = .9f;
-uniform float contrast = 20.f;
-uniform float intExp = 0.f;
-uniform float scale = 1.f;
-
-//uniform float multiplier = .5f;
-//uniform float contrast = 1.5f;
+//uniform float multiplier = .9f;
+//uniform float contrast = 20.f;
//uniform float intExp = 0.f;
//uniform float scale = 1.f;
+uniform float multiplier = .5f;
+uniform float contrast = 1.5f;
+uniform float intExp = 0.f;
+uniform float scale = 1.f;
+
//uniform vec4 baseColor =vec4();
void main() {
@@ -39,4 +39,5 @@ void main() {
finalInt = clamp(finalInt, 0, 1);
fragColor = vec4(1, 1, 1, finalInt * scale);
// fragColor = vec4(vec3(1), pow(oldArea / newArea * .2f, 1.5f));
+ fragColor = vec4((normal_worldSpace + 1) / 2, 1.f);
}
diff --git a/resources/shaders/color.vert b/resources/shaders/color.vert
index 677abf6..d607ff9 100644
--- a/resources/shaders/color.vert
+++ b/resources/shaders/color.vert
@@ -4,7 +4,7 @@ layout(location = 0) in vec3 position; // Position of the vertex
layout(location = 1) in vec3 normal; // Normal of the vertex
layout(location = 2) in vec3 texCoords; // Normal of the vertex
-uniform float depth = -3000.f;
+uniform float depth = -1000.f;
uniform float skyHeight = 500.f;
uniform mat4 proj;
uniform mat4 view;
@@ -89,4 +89,5 @@ void main() {
oldPosFlat = moveToTopDown(position);
pos = moveToTopDown(vec3(refractedPositionAndProb));
gl_Position = vec4(pos, 1.f);
+ gl_Position = vec4(oldPosFlat, 1.f);
}
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag
index 88c783d..1b73b96 100755
--- a/resources/shaders/shader.frag
+++ b/resources/shaders/shader.frag
@@ -71,6 +71,7 @@ void main() {
vec2 reflUV = uvFromWorldPoint(reflPos);
// float waterMurkiness = 0.002f; // TODO: Make uniform
+// float waterMurkiness = 0.0005f; // TODO: Make uniform
float waterMurkiness = 0.0005f; // TODO: Make uniform
vec3 waterVolumeColor = vec3(red * 0.1f, green * 0.2f, blue * 0.2f);
float murkDiffuse = 0.3f;
diff --git a/src/arap.cpp b/src/arap.cpp
index 6239f83..b6f2f8c 100644
--- a/src/arap.cpp
+++ b/src/arap.cpp
@@ -66,41 +66,7 @@ void ARAP::init
// minCorner = Vector3f(-1.0f, -1.0f, -1.0f);
// maxCorner = Vector3f(1.0f, 1.0f, 1.0f);
-
-// m_shape.initGroundPlane("cornell_box_full_lighting.png")
-// QImage ocean_floor_image;
-// GLuint ocean_floor_texture;
-// // Prepare filepath
-// QString ocean_floor_filepath = QString(":/resources/images/kitten.png");
-
-// // TASK 1: Obtain image from filepath
-// ocean_floor_image = QImage(ocean_floor_filepath);
-
-// // TASK 2: Format image to fit OpenGL
-// ocean_floor_image = ocean_floor_image.convertToFormat(QImage::Format_RGBA8888).mirrored();
-
-// // TASK 3: Generate kitten texture
-// glGenTextures(1, &ocean_floor_texture);
-
-// // TASK 9: Set the active texture slot to texture slot 0
-// glActiveTexture(GL_TEXTURE0);
-
-// // TASK 4: Bind kitten texture
-// glBindTexture(GL_TEXTURE_2D, ocean_floor_texture);
-
-// // TASK 5: Load image into kitten texture
-// glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, ocean_floor_image.width(), ocean_floor_image.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, ocean_floor_image.bits());
-
-// // TASK 6: Set min and mag filters' interpolation mode to linear
-// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
-// glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
-
-// // TASK 7: Unbind kitten texture
-// glBindTexture(GL_TEXTURE_2D, 0);
-
-// // TASK 10: set the texture.frag uniform for our texture
-// glUseProgram(m_texture_shader);
-// glUniform1i(glGetUniformLocation(m_texture_shader, "sampler"), 0);
+ initCausticsShape(10);
}
void ARAP::update(double seconds)
@@ -117,27 +83,27 @@ void ARAP::update(double seconds)
// Note that the "seconds" parameter represents the amount of time that has passed since
// the last update
m_ocean.fft_prime(m_time);
- m_ocean.update_ocean();
- m_shape.setVertices_and_Normals(m_ocean.get_vertices(), m_ocean.getNormals());
- // m_shape.setVertices(m_ocean.get_vertices());
+ m_ocean.update_ocean();
+// m_shape.setVertices_and_Normals(m_ocean.get_vertices(), m_ocean.getNormals());
+ m_shape.setVertices(m_ocean.get_vertices());
- auto tmp = m_ocean.get_vertices();
+// auto tmp = m_ocean.get_vertices();
// print the min and max of the vertices
- Vector3f min = Vector3f::Ones() * 1000000;
- Vector3f max = Vector3f::Ones() * -1000000;
- for (int i = 0; i < tmp.size(); i++) {
- min = min.cwiseMin(tmp[i]);
- max = max.cwiseMax(tmp[i]);
- }
- std::cout << "min: " << min << std::endl;
-std::cout << "max: " << max << std::endl;
+// Vector3f min = Vector3f::Ones() * 1000000;
+// Vector3f max = Vector3f::Ones() * -1000000;
+// for (int i = 0; i < tmp.size(); i++) {
+// min = min.cwiseMin(tmp[i]);
+// max = max.cwiseMax(tmp[i]);
+// }
+// std::cout << "min: " << min << std::endl;
+//std::cout << "max: " << max << std::endl;
FoamConstants foam = m_ocean.getFoamConstants();
m_foam_shape.setFoamInputs(m_shape.getVertices(), foam.wavelengths, foam.k_vectors, foam.texCoords);
m_time += m_timestep;
- // std::cout << m_time << std::endl;
+// std::cout << m_time << std::endl;
}
// Move an anchored vertex, defined by its index, to targetPosition
@@ -162,3 +128,64 @@ void ARAP::move
// - Minus and equal keys (click repeatedly) to change the size of the vertices
}
+void ARAP::initCausticsShape(int res) {
+// std::vector<Eigen::Vector3f> gridPoints;
+// float step = 2.f / ((float) res);
+
+// for (int i = 0; i < res; ++i) {
+// for (int j = 0; j < res; ++j) {
+// float x = -1.f + i * step; // calculate x coordinate
+// float y = -1.f + j * step; // calculate y coordinate
+// gridPoints.push_back(Eigen::Vector3f(x, y, 0.f)); // add point to grid
+// }
+// }
+// std::vector<Eigen::Vector3f> verts;
+// float step = 2.f / ((float) res);
+
+// for (int i = 0; i < res; ++i) {
+// for (int j = 0; j < res; ++j) {
+// float x = -1.f + i * step; // calculate x coordinate
+// float y = -1.f + j * step; // calculate y coordinate
+// Eigen::Vector3f bottomLeft = Eigen::Vector3f(x, y, 0.f);
+// Eigen::Vector3f bottomRight = Eigen::Vector3f(x + step, y, 0.f);
+// Eigen::Vector3f topRight = Eigen::Vector3f(x + step, y + step, 0.f);
+// Eigen::Vector3f topLeft = Eigen::Vector3f(x, y + step, 0.f);
+// verts.push_back(topLeft);
+// verts.push_back(bottomLeft);
+// verts.push_back(bottomRight);
+// verts.push_back(topLeft);
+// verts.push_back(bottomRight);
+// verts.push_back(topRight);
+// }
+// }
+// m_causticsShape.setVertices(verts);
+ std::vector<Eigen::Vector3f> verts;
+ std::vector<Eigen::Vector3i> faces;
+ float size = 2.f;
+ float step = size / ((float) res);
+
+ for (int i = 0; i <= res; ++i) {
+ for (int j = 0; j <= res; ++j) {
+ float x = -(size / 2.f) + i * step; // calculate x coordinate
+ float y = -(size / 2.f) + j * step; // calculate y coordinate
+ Eigen::Vector3f bottomLeft = Eigen::Vector3f(x, y, 0.f);
+ verts.push_back(bottomLeft);
+ }
+ }
+
+ for (int i = 0; i < res; ++i) {
+ for (int j = 0; j < res; ++j) {
+ int bottomLeft = i * (res + 1) + j;
+ int bottomRight = i * (res + 1) + j + 1;
+ int topRight = (i + 1) * (res + 1) + j + 1;
+ int topLeft = (i + 1) * (res + 1) + j;
+ faces.push_back(Eigen::Vector3i(topLeft, bottomLeft, bottomRight));
+ faces.push_back(Eigen::Vector3i(topLeft, bottomRight, topRight));
+ faces.push_back(Eigen::Vector3i(bottomRight, bottomLeft, topLeft));
+ faces.push_back(Eigen::Vector3i(topRight, bottomRight, topLeft));
+ }
+ }
+ m_causticsShape.init(verts, faces);
+ m_causticsShape.setColor(0.27f, .803f, .96f);
+}
+
diff --git a/src/arap.h b/src/arap.h
index e5529d9..39b2076 100644
--- a/src/arap.h
+++ b/src/arap.h
@@ -1,6 +1,7 @@
#pragma once
#include "graphics/shape.h"
+//#include "graphics/simpleshape.h"
//#include "graphics/oceanshape.h"
#include "Eigen/StdList"
#include "Eigen/StdVector"
@@ -22,6 +23,8 @@ private:
Shape m_foam_shape;
+// OceanShape m_oceanShape;
+ void initCausticsShape(int res);
public:
ARAP();
@@ -39,8 +42,7 @@ public:
void draw(Shader *shader, GLenum mode)
{
-
-
+// m_causticsShape.draw(shader, mode);
m_shape.draw(shader, mode);
}
@@ -99,5 +101,7 @@ public:
double m_timestep = 0.3;
Eigen::Vector3f minCorner, maxCorner;
+
+ Shape m_causticsShape;
};
diff --git a/src/glwidget.cpp b/src/glwidget.cpp
index 91d38bc..47df4f5 100755
--- a/src/glwidget.cpp
+++ b/src/glwidget.cpp
@@ -110,6 +110,7 @@ void GLWidget::initializeGL()
m_foam_tex = loadTextureFromFile(":resources/images/foam3.png").textureID;
+ m_causticsShader = new Shader(":resources/shaders/caustics.vert", ":resources/shaders/caustics.frag");
initCaustics();
@@ -138,11 +139,12 @@ void GLWidget::initializeGL()
m_devicePixelRatio = this->devicePixelRatio();
- m_defaultFBO = 2;
+ m_defaultFBO = 3;
m_fbo_width = size().width() * m_devicePixelRatio;
m_fbo_height = size().height() * m_devicePixelRatio;
makeFBO();
+ makeFBO1();
// FBO STUFF END
@@ -209,7 +211,7 @@ void GLWidget::paintCaustics() {
glClearColor(0.68f, 0.58f, 0.38f, 1);
// glClearColor(0., 0., 0., 1);
- glBindFramebuffer(GL_FRAMEBUFFER, m_fbo);
+ glBindFramebuffer(GL_FRAMEBUFFER, m_fbo1);
// glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO);
// Clear Screen
@@ -227,6 +229,7 @@ void GLWidget::paintCaustics() {
//// // Draw the VAO
// glDrawArrays(GL_TRIANGLES, 0, 3);
+
m_colorShader->bind();
//
m_colorShader->setUniform("proj", m_camera.getProjection());
@@ -243,6 +246,24 @@ void GLWidget::paintCaustics() {
// Unbind the shader
glUseProgram(0);
+
+ m_causticsShader->bind();
+
+// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+
+ glBindFramebuffer(GL_FRAMEBUFFER, m_fbo_texture);
+ glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
+ glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
+ glEnable( GL_BLEND );
+ glDisable( GL_DEPTH_TEST );
+
+ glActiveTexture(GL_TEXTURE2);
+ glBindTexture(GL_TEXTURE_2D, m_fbo_texture1);
+ glUniform1i(glGetUniformLocation(m_causticsShader ->id(), "normSamp"), 2);
+
+ m_arap.m_causticsShape.draw(m_causticsShader, GL_TRIANGLES);
+ glBindVertexArray(0);
+ glUseProgram(0);
}
void GLWidget::initCaustics() {
@@ -345,7 +366,37 @@ void GLWidget::makeFBO() {
// Task 22
glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO);
+}
+void GLWidget::makeFBO1() {
+ // Task 19
+ glActiveTexture(GL_TEXTURE2);
+ glGenTextures(1, &m_fbo_texture1);
+ glBindTexture(GL_TEXTURE_2D, m_fbo_texture1);
+ glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, m_fbo_width, m_fbo_height, 0, GL_RGB, GL_UNSIGNED_BYTE, NULL);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
+ glBindTexture(GL_TEXTURE_2D, 0);
+
+ // Task 20
+ glGenRenderbuffers(1, &m_fbo_renderbuffer1);
+ glBindRenderbuffer(GL_RENDERBUFFER, m_fbo_renderbuffer1);
+ glRenderbufferStorage(GL_RENDERBUFFER,
+ GL_DEPTH24_STENCIL8,
+ m_fbo_width,
+ m_fbo_height);
+ glBindRenderbuffer(GL_RENDERBUFFER, 0);
+
+ // Task 18
+ glGenFramebuffers(1, &m_fbo1);
+ glBindFramebuffer(GL_FRAMEBUFFER, m_fbo1);
+
+ // Task 21
+ glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, m_fbo_texture1, 0);
+ glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_STENCIL_ATTACHMENT, GL_RENDERBUFFER, m_fbo_renderbuffer1);
+
+ // Task 22
+ glBindFramebuffer(GL_FRAMEBUFFER, m_defaultFBO);
}
void GLWidget::paintGL()
@@ -358,6 +409,7 @@ void GLWidget::paintGL()
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable( GL_BLEND );
+ glEnable(GL_DEPTH_TEST);
m_defaultShader->bind();
m_defaultShader->setUniform("proj", m_camera.getProjection());
@@ -517,7 +569,11 @@ void GLWidget::resizeGL(int w, int h)
glDeleteTextures(1, &m_fbo_texture);
glDeleteRenderbuffers(1, &m_fbo_renderbuffer);
glDeleteFramebuffers(1, &m_fbo);
+ glDeleteTextures(1, &m_fbo_texture1);
+ glDeleteRenderbuffers(1, &m_fbo_renderbuffer1);
+ glDeleteFramebuffers(1, &m_fbo1);
makeFBO();
+ makeFBO1();
}
// ================== Event Listeners
diff --git a/src/glwidget.h b/src/glwidget.h
index 006f027..d992ab6 100755
--- a/src/glwidget.h
+++ b/src/glwidget.h
@@ -47,6 +47,7 @@ private:
void keyReleaseEvent (QKeyEvent *event) override;
void makeFBO();
+ void makeFBO1();
void initCaustics();
void paintCaustics();
@@ -65,6 +66,7 @@ private:
Shader *m_defaultShader;
Shader *m_pointShader;
Shader *m_texture_shader;
+ Shader *m_causticsShader;
Shader *m_colorShader;
Shader *m_foamShader;
@@ -84,6 +86,11 @@ private:
GLuint m_fbo;
GLuint m_fbo_texture;
GLuint m_fbo_renderbuffer;
+
+ GLuint m_fbo1;
+ GLuint m_fbo_texture1;
+ GLuint m_fbo_renderbuffer1;
+
GLuint m_defaultFBO;
GLuint m_floor_vbo;