summaryrefslogtreecommitdiff
path: root/resources/shaders
diff options
context:
space:
mode:
authorjjesswan <90643397+jjesswan@users.noreply.github.com>2024-05-09 15:13:41 -0400
committerGitHub <noreply@github.com>2024-05-09 15:13:41 -0400
commitf846ddba00aee29675f0bd4f5dbc87a94a422368 (patch)
tree65a857125b91502974bceb40e24c1c7eff4bad59 /resources/shaders
parent72bcf6a346dfcaeaac9520d8c524711192e77c3d (diff)
parent675391d07f50d0067e7bab983433c6d86f5f8256 (diff)
Merge pull request #3 from Seb-Park/foam2
Foam2 merge -- foam, skybox
Diffstat (limited to 'resources/shaders')
-rw-r--r--resources/shaders/foam.frag53
-rw-r--r--resources/shaders/foam.vert56
-rw-r--r--resources/shaders/skybox.frag24
-rw-r--r--resources/shaders/skybox.vert21
4 files changed, 154 insertions, 0 deletions
diff --git a/resources/shaders/foam.frag b/resources/shaders/foam.frag
new file mode 100644
index 0000000..be95183
--- /dev/null
+++ b/resources/shaders/foam.frag
@@ -0,0 +1,53 @@
+#version 330 core
+
+in vec2 constants;
+in vec2 dir;
+in vec2 tex;
+in vec3 pos;
+
+
+uniform float time;
+uniform float phaseC; // phase constant
+
+uniform sampler2D halftone_texture;
+uniform sampler2D foam_texture;
+
+uniform vec2 widthBounds;
+uniform vec2 lengthBounds;
+
+out vec4 fragColor;
+
+float getSaturation(vec2 k, vec2 xzPos, float adjWaveLength, float phaseC){
+ //k = normalize(k);
+ float result = dot(k, xzPos) * 3.14f / adjWaveLength;
+ result = result + phaseC*time*.5f;
+ result = -tan(result + 1.57f);
+ result = exp(result) / 20.f;
+
+ return result;
+
+}
+
+
+
+void main() {
+ float height = pos.y;
+ float saturation = constants[0];//getSaturation(dir, vec2(pos.x, pos.z), 200.f, constants[0]);
+ vec4 m_uv = texture(halftone_texture, tex*2);
+ float m_threshold = (m_uv.r + m_uv.g + m_uv.b) / 3;
+
+ // final rgba color at x,z pos
+ vec4 h = vec4(0,0,1,1);
+ if (saturation > m_threshold) h = vec4(1,1,1, 1);
+
+ // add fading effect to bubble popping
+ vec4 g = clamp(saturation - m_threshold, 0, 1) * h;
+
+ // apply foam texture
+ vec4 foam = texture(foam_texture, tex + time*.0003);
+ vec4 j = vec4(0,0,0,0);
+ if (saturation > m_threshold) j = g*foam*1.8;
+
+
+ fragColor = j; //vec4(vec3(g), 1);
+}
diff --git a/resources/shaders/foam.vert b/resources/shaders/foam.vert
new file mode 100644
index 0000000..f27c589
--- /dev/null
+++ b/resources/shaders/foam.vert
@@ -0,0 +1,56 @@
+#version 330 core
+
+layout(location = 0) in vec3 position; // Position of the vertex
+layout(location = 1) in vec3 wavelength; // wavelenth adjusted for ocean depth
+layout(location = 2) in vec3 wavedirs; // wavelenth adjusted for ocean depth
+
+//layout(location = 2) in vec2 direction; // wave slope
+//layout(location = 3) in vec2 texCoords; // texture coords
+//layout(location = 3) in vec3 norm; // texture coords
+
+
+out vec2 constants;
+out vec2 dir;
+out vec2 tex;
+out vec3 pos;
+
+
+
+uniform float time;
+uniform float phaseC; // phase constant
+uniform mat4 proj;
+uniform mat4 view;
+uniform mat4 model;
+uniform mat4 inverseView;
+uniform vec2 widthBounds;
+uniform vec2 lengthBounds;
+
+vec2 calculateTexCoord(vec3 pos){
+// vec3 v = vec3(0,0,1);
+// if (abs(norm.y) < 1.f){
+// v = normalize(vec3(0,1,0) - norm.y*norm);
+// }
+// vec3 u = normalize(cross(norm, v));
+
+// float u_coord = dot(u, vec3(pos.x, 0, pos.z)) - widthBounds[0]/ (widthBounds[1] - widthBounds[0]);
+// float v_coord = dot(v, vec3(pos.x, 0, pos.z)) - lengthBounds[0]/ (lengthBounds[1] - lengthBounds[0]);
+
+ float u_coord = position.x / (widthBounds[1] - widthBounds[0]);
+ float v_coord = position.z / (lengthBounds[1] - lengthBounds[0]);
+
+
+ float offset = .5f;
+ return 2*vec2(u_coord + offset, v_coord + offset);
+
+}
+
+void main() {
+ dir = vec2(wavedirs[0],wavedirs[1]);
+ constants = vec2(wavelength[0], phaseC);
+
+ gl_Position = proj * view * model * vec4(position, 1);
+ pos = vec3(gl_Position);
+
+ tex = calculateTexCoord(position);
+
+}
diff --git a/resources/shaders/skybox.frag b/resources/shaders/skybox.frag
new file mode 100644
index 0000000..926807e
--- /dev/null
+++ b/resources/shaders/skybox.frag
@@ -0,0 +1,24 @@
+
+#version 330 core
+
+in vec3 tex_coord;
+
+uniform samplerCube cubeMap;
+uniform vec3 skyColor;
+
+out vec4 fragColor;
+
+const float lowerLimit = -50000.f;
+const float upperLimit = 50000.f;
+
+
+void main() {
+
+ //fragColor = vec4(1.f);
+ vec4 finalColor = texture(cubeMap, tex_coord);
+
+ // blending bottom of skybox to skyColor
+ float factor = (tex_coord.y - lowerLimit) / (upperLimit - lowerLimit);
+ factor = clamp(factor, 0.f, 1.f);
+ fragColor = finalColor; // mix(vec4(skyColor, 1.f), finalColor, factor);
+}
diff --git a/resources/shaders/skybox.vert b/resources/shaders/skybox.vert
new file mode 100644
index 0000000..edf50e4
--- /dev/null
+++ b/resources/shaders/skybox.vert
@@ -0,0 +1,21 @@
+#version 330 core
+
+layout(location = 0) in vec3 pos; // Position of the vertex
+//layout(location = 1) in vec3 normal; // Normal of the vertex
+//layout(location = 3) in vec3 texCoords;
+
+uniform mat4 view, projection, rotation;
+
+out vec3 tex_coord;
+
+
+
+void main() {
+
+ tex_coord = vec3(pos.x, pos.y, -pos.z);
+ vec4 world_pos = projection*view*rotation*vec4(pos, 1.0);
+ gl_Position = vec4(world_pos.x, world_pos.y, world_pos.w, world_pos.w);
+
+// tex_coord = pos;
+ // gl_Position = projection*view*vec4(pos, 1.0);
+}