summaryrefslogtreecommitdiff
path: root/resources/shaders/shader.frag
diff options
context:
space:
mode:
Diffstat (limited to 'resources/shaders/shader.frag')
-rwxr-xr-xresources/shaders/shader.frag44
1 files changed, 35 insertions, 9 deletions
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag
index fc78890..7df2588 100755
--- a/resources/shaders/shader.frag
+++ b/resources/shaders/shader.frag
@@ -8,6 +8,7 @@ in vec3 pos;
in vec3 refrPos;
in float refrProb;
in vec2 uv;
+in float matIor;
uniform sampler2D texture_img;
@@ -22,6 +23,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]);
@@ -47,21 +62,32 @@ void main() {
// fragColor = vec4(fragColor.x, 0.f, fragColor.z, 1.f);
// fragColor = vec4(test, test, test, 1.f);
vec2 refrUV = uvFromWorldPoint(refrPos);
- vec4 transmissive = vec4(vec3(refrUV, 1.f - refrUV.y), 1.f);
+ 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);
+ float waterBlurriness = 0.f;
+ vec2 refrUVBlurry = (1 - beerAtt) * vec2(rand(refrUV), rand(vec4(pos, d))) * waterBlurriness + refrUV;
+ vec4 transmissive = texture(sampler, vec2(refrUVBlurry));
+
+// refrProb *= beerAtt;
- fragColor = 0.25f * vec4(red * d, green * d, blue * d, 1.0f); // Diffuse
- fragColor += 0.75f * vec4(1, 1, 1, 1) * pow(spec, 10.f); // Specular TODO: Pass multiplications as uniforms.
+ fragColor = 0.75f * diffuse; // Diffuse
+ fragColor += 0.6f * specular; // Specular TODO: Pass multiplications as uniforms.
fragColor = clamp(fragColor, 0.f, 1.f); // Clamp
- fragColor *= (1 - (refrProb / 1.f));
- fragColor += (refrProb / 1.5f) * transmissive;
+ fragColor *= (1 - ((beerAtt * refrProb) / 1.f));
+ fragColor += ((beerAtt * refrProb) / 1.5f) * transmissive;
// fragColor = transmissive * refrProb;
fragColor = vec4(vec3(fragColor), 1.5f);
// Dividing refrProb by 2 just for heuristic. Want more phong to show through.
// fragColor = clamp(fragColor, 0.f, 1.f);
// fragColor = vec4(refrProb, 0.f, 0.f, 1.f);
-
- // assign texture
- fragColor = texture(texture_img, uv);
-
+ // TODO: ACTUAL LIGHTING MODEL SHOULD BE SOMETHING LIKE
+ // 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));
}