summaryrefslogtreecommitdiff
path: root/resources/shaders/shader.frag
diff options
context:
space:
mode:
authorSebastian Park <SebPark03@gmail.com>2024-04-17 03:10:27 -0400
committerSebastian Park <SebPark03@gmail.com>2024-04-17 03:10:27 -0400
commit9b436e67cdc5ee896c3c2fec90499e400a9e524e (patch)
tree45366352db1024722bbe7db07792c4148683afa9 /resources/shaders/shader.frag
parent0b0629450e2553b2f890094290528b565d607e38 (diff)
Do realtime refraction kinda.
Diffstat (limited to 'resources/shaders/shader.frag')
-rwxr-xr-xresources/shaders/shader.frag29
1 files changed, 27 insertions, 2 deletions
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag
index d2183cc..66a36d0 100755
--- a/resources/shaders/shader.frag
+++ b/resources/shaders/shader.frag
@@ -5,20 +5,45 @@ in vec3 normal_cameraSpace;
in vec3 camera_worldSpace;
in vec3 normal_worldSpace;
in vec3 pos;
+in vec3 refrPos;
+in vec2 uv;
uniform int wire = 0;
uniform float red = 1.0;
uniform float green = 1.0;
uniform float blue = 1.0;
uniform float alpha = 1.0;
+uniform sampler2D sampler;
+uniform vec2 widthBounds;
+uniform vec2 lengthBounds;
+//uniform float test = 0;
+
+vec2 uvFromWorldPoint(vec3 point) {
+ float u = (point.x - widthBounds[0]) / (widthBounds[1] - widthBounds[0]);
+ float v = (point.z - lengthBounds[0]) / (lengthBounds[1] - lengthBounds[0]);
+ return vec2(u, v);
+}
void main() {
// Do lighting in camera space
vec3 lightDir = normalize(vec3(0, 0.5, 1));
- float d = clamp(dot(normal_cameraSpace, lightDir), 0, 1);
+ lightDir = normalize(vec3(0.f, 3.f, 0.f) - pos);
+// float d = clamp(dot(normal_cameraSpace, lightDir), 0, 1);
+ float d = clamp(dot(normal_worldSpace, lightDir), 0, 1);
vec3 reflectedLight = lightDir - 2 * dot(lightDir, normal_worldSpace) * normal_worldSpace;
vec3 posToCam = normalize(camera_worldSpace - pos);
float spec = pow(dot(posToCam, reflectedLight), 2.f);
- fragColor = clamp(0.5f * vec4(red * d, green * d, blue * d, 0.5f) + 0.5f * vec4(1, 1, 1, 1) * spec, 0, 1);
+// fragColor = texture(sampler, vec2(0.5f, 0.5f));
+// fragColor = vec4(abs(pos.x / 160.f), pos.y, 0.f, 1.f);
+// fragColor = vec4(uv.y, uv.y, 0.f, 1.f);
+// fragColor = vec4(camera_worldSpace.x - pos[0], camera_worldSpace.y - pos[1], pos[2], 1.f);
+// fragColor = vec4(- pos[0], 0.f, 0.f, 1.f);
+// fragColor = vec4((pos - vec3(widthBounds[0], 0, lengthBounds[0])) / 5.f, 1.f);
+// fragColor = vec4(fragColor.x, 0.f, fragColor.z, 1.f);
+// fragColor = vec4(test, test, test, 1.f);
+ fragColor = vec4(vec3(uvFromWorldPoint(refrPos), 0.f), 1.f);
+
+// fragColor = clamp(0.5f * vec4(red * d, green * d, blue * d, 0.5f) + 0.5f * vec4(1, 1, 1, 1) * spec, 0, 1);
+
}