summaryrefslogtreecommitdiff
path: root/resources
diff options
context:
space:
mode:
authorSebastian Park <SebPark03@gmail.com>2024-04-23 00:30:37 -0400
committerSebastian Park <SebPark03@gmail.com>2024-04-23 00:30:37 -0400
commitf2d61fc06387ccb22ecb5cb6c42210736ac64c9f (patch)
tree9191e1e91a79514a5231dc6e50c2ecc4feb03b16 /resources
parentb4be9e522b51b01c7870821648e85f97c1fdb09b (diff)
Get ground textures working, but not yet abstracted to the shape class.
Diffstat (limited to 'resources')
-rw-r--r--resources/images/sand_text.jpgbin0 -> 23150 bytes
-rw-r--r--resources/images/uv1 copy.pngbin48020 -> 0 bytes
-rw-r--r--resources/images/uv1.pngbin86064 -> 48020 bytes
-rw-r--r--resources/images/uv1_cut.pngbin0 -> 86064 bytes
-rwxr-xr-xresources/shaders/shader.frag23
-rwxr-xr-xresources/shaders/shader.vert14
-rw-r--r--resources/shaders/texture.frag24
-rw-r--r--resources/shaders/texture.vert15
8 files changed, 67 insertions, 9 deletions
diff --git a/resources/images/sand_text.jpg b/resources/images/sand_text.jpg
new file mode 100644
index 0000000..6a64486
--- /dev/null
+++ b/resources/images/sand_text.jpg
Binary files differ
diff --git a/resources/images/uv1 copy.png b/resources/images/uv1 copy.png
deleted file mode 100644
index fcf4825..0000000
--- a/resources/images/uv1 copy.png
+++ /dev/null
Binary files differ
diff --git a/resources/images/uv1.png b/resources/images/uv1.png
index 82ff8ac..fcf4825 100644
--- a/resources/images/uv1.png
+++ b/resources/images/uv1.png
Binary files differ
diff --git a/resources/images/uv1_cut.png b/resources/images/uv1_cut.png
new file mode 100644
index 0000000..82ff8ac
--- /dev/null
+++ b/resources/images/uv1_cut.png
Binary files differ
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag
index 82a0387..2e4e780 100755
--- a/resources/shaders/shader.frag
+++ b/resources/shaders/shader.frag
@@ -20,6 +20,20 @@ uniform vec2 widthBounds;
uniform vec2 lengthBounds;
//uniform float test = 0;
+float rand(vec2 n) {
+ return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453);
+}
+
+float rand(float n) {
+ return fract(sin(n) * 43758.5453123);
+}
+
+float rand(vec4 n) {
+// vec2 first2 = vec2(n[0], n[1]);
+//// return 1.f;
+ return rand(vec2(n[0] * rand(n[2]), n[1] * rand(n[3])));
+}
+
vec2 uvFromWorldPoint(vec3 point) {
float u = (point.x - widthBounds[0]) / (widthBounds[1] - widthBounds[0]);
float v = (point.z - lengthBounds[0]) / (lengthBounds[1] - lengthBounds[0]);
@@ -45,11 +59,14 @@ void main() {
// fragColor = vec4(fragColor.x, 0.f, fragColor.z, 1.f);
// fragColor = vec4(test, test, test, 1.f);
vec2 refrUV = uvFromWorldPoint(refrPos);
- float beerAtt = exp(-length((pos - refrPos)) * 2.0f); // TODO: Make uniform
+ float beerAtt = exp(-length((pos - refrPos)) * 0.2f); // TODO: Make uniform
vec4 diffuse = vec4(red * d, green * d, blue * d, 1.0f);
vec4 specular = vec4(1, 1, 1, 1) * pow(spec, 10.f);
- vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f);
+// vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f);
+ float waterBlurriness = 0.1f;
+ vec2 refrUVBlurry = (1 - beerAtt) * vec2(rand(refrUV), rand(vec4(pos, d))) * waterBlurriness + refrUV;
+ vec4 transmissive = texture(sampler, vec2(refrUVBlurry));
// refrProb *= beerAtt;
@@ -68,4 +85,6 @@ void main() {
// VELOCITY * DIFFUSE
// (1 - refrProb) * SPECULAR
// refrProb * (BEER * TRANSMISSIVE + (1 - beerAtt) * VOLUME (which is somewhat diffuse too?))
+ // Transmissive shouldn't just get darker, but blurrier as beer attenuation lowers.
+// fragColor = texture(sampler, vec2(refrUV));
}
diff --git a/resources/shaders/shader.vert b/resources/shaders/shader.vert
index fbb9950..3271498 100755
--- a/resources/shaders/shader.vert
+++ b/resources/shaders/shader.vert
@@ -22,7 +22,7 @@ out vec2 uv;
out float matIor;
vec4 getRefrPos() {
- float depth = -1.f; // TODO: Pass as uniform
+ float depth = -3.f; // TODO: Pass as uniform
vec3 w_o = normalize(pos - camera_worldSpace);
float cos_theta_i = dot(-w_o, normal_worldSpace);
float n_i = 1;
@@ -52,8 +52,8 @@ vec4 getRefrPos() {
}
void main() {
- float depth = -2.f;
- float dist = position.y - depth;
+// float depth = -4.f;
+// float dist = position.y - depth;
float width = 81.f * 2.f;
float length = 81.f * 2.f;
matIor = 1.33f;
@@ -64,10 +64,10 @@ void main() {
pos = vec3(model * vec4(position, 1.f)); //vec3(model * vec4(objSpacePos, 1.f));
// pos = position;
- float depthScale = dist / normal.y;
- vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground
- groundContactPoint = vec3(model * vec4(position, 1));
- uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z);
+// float depthScale = dist / normal.y;
+// vec3 groundContactPoint = -(normal * depthScale) + position; // carries down to ground
+// groundContactPoint = vec3(model * vec4(position, 1));
+// uv = vec2((position.x + 81.f) / (162.f), groundContactPoint.z);
// uv = vec2(normal);
vec4 refrPos_and_prob = getRefrPos();
refrPos = vec3(refrPos_and_prob);
diff --git a/resources/shaders/texture.frag b/resources/shaders/texture.frag
new file mode 100644
index 0000000..c7a5956
--- /dev/null
+++ b/resources/shaders/texture.frag
@@ -0,0 +1,24 @@
+#version 330 core
+
+// TASK 16: Create a UV coordinate in variable
+in vec2 uv;
+
+// TASK 8: Add a sampler2D uniform
+uniform sampler2D sampler;
+
+// TASK 29: Add a bool on whether or not to filter the texture
+uniform bool filtered;
+
+out vec4 fragColor;
+
+void main()
+{
+ // TASK 17: Set fragColor using the sampler2D at the UV coordinate
+ fragColor = texture(sampler, uv);
+
+ // TASK 33: Invert fragColor's r, g, and b color channels if your bool is true
+ if(filtered){
+ fragColor = vec4(1) - fragColor;
+ fragColor.w = 1;
+ }
+}
diff --git a/resources/shaders/texture.vert b/resources/shaders/texture.vert
new file mode 100644
index 0000000..c87f366
--- /dev/null
+++ b/resources/shaders/texture.vert
@@ -0,0 +1,15 @@
+#version 330 core
+
+// TASK 15: add a second layout variable representing a UV coordinate
+layout (location = 0) in vec3 position;
+layout (location = 1) in vec2 uv_raw;
+
+// TASK 16: create an "out" variable representing a UV coordinate
+out vec2 uv;
+
+void main() {
+ // TASK 16: assign the UV layout variable to the UV "out" variable
+ uv = uv_raw;
+
+ gl_Position = vec4(position, 1.0);
+}