summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Park <SebPark03@gmail.com>2024-04-23 18:05:10 -0400
committerSebastian Park <SebPark03@gmail.com>2024-04-23 18:05:10 -0400
commite0f2b36de8b3e842a6af4bf18f7427213185c925 (patch)
tree1ced1bbd7ff7f486c11658900c2255a033ba528b
parent5c8c2f86376050787f2960656ca5865fcf87c020 (diff)
parent37b6e9063dad88722d0063759af7b8f3b3fbc127 (diff)
Merge branch 'shaders'
-rwxr-xr-xresources/shaders/shader.frag30
1 files changed, 21 insertions, 9 deletions
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag
index 3beefa6..ea7569b 100755
--- a/resources/shaders/shader.frag
+++ b/resources/shaders/shader.frag
@@ -45,13 +45,13 @@ vec2 uvFromWorldPoint(vec3 point) {
void main() {
// Do lighting in camera space
- vec3 lightDir = normalize(vec3(1, 0.5, 1));
- // lightDir = normalize(vec3(0.f, 3.f, 0.f) - pos);
+ vec3 lightDir = -normalize(vec3(1, -1, 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);
+ float spec = pow(clamp(dot(posToCam, reflectedLight), 0, 1), 2.f);
// fragColor = texture(sampler, vec2(0.5f, 0.5f));
// fragColor = vec4(abs(pos.x / 160.f), pos.y, 0.f, 1.f);
@@ -62,7 +62,13 @@ 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)) * 0.001f); // TODO: Make uniform
+ float waterMurkiness = 0.002f; // TODO: Make uniform
+ vec3 waterVolumeColor = vec3(red * 0.1f, green * 0.2f, blue * 0.2f);
+ float murkDiffuse = 0.3f;
+ float murkAmbient = 0.8f;
+ float beerAtt = exp(-length((pos - refrPos)) * waterMurkiness);
+ // EXPLANATION: WHEN THE WATER IS NOT PERFECTLY CLEAR, IT WILL HAVE STUFF SCATTERING LIGHT UNDERNEATH THE SURFACE
+ // SOME OF IT WILL BE DIFFUSELY LIT, BUT THERE WILL BE SUBSURFACE SCATTERING, ESTIMATED BY THE AMBIENT TERM
vec4 diffuse = vec4(red * d, green * d, blue * d, 1.0f);
vec4 specular = vec4(1, 1, 1, 1) * pow(spec, 10.f);
@@ -70,14 +76,20 @@ void main() {
float waterBlurriness = 0.f;
vec2 refrUVBlurry = (1 - beerAtt) * vec2(rand(refrUV), rand(vec4(pos, d))) * waterBlurriness + refrUV;
vec4 transmissive = texture(sampler, vec2(refrUVBlurry));
+ vec4 murk = (vec4(waterVolumeColor * d * murkDiffuse + waterVolumeColor * murkAmbient, 1.0f));
// refrProb *= beerAtt;
fragColor = 0.75f * diffuse; // Diffuse
- fragColor += 0.6f * specular; // Specular TODO: Pass multiplications as uniforms.
+ fragColor = vec4(0,0,0,0);
+ fragColor += 1.f * specular; // Specular TODO: Pass multiplications as uniforms.
fragColor = clamp(fragColor, 0.f, 1.f); // Clamp
- fragColor *= (1 - ((beerAtt * refrProb) / 1.f));
- fragColor += ((beerAtt * refrProb) / 1.5f) * transmissive;
+ fragColor *= ((1 - refrProb) / 1.f);
+
+ vec4 volumetric = beerAtt * transmissive;
+ volumetric += (1 - beerAtt) * murk;
+
+ fragColor += refrProb * volumetric;
// fragColor = transmissive * refrProb;
fragColor = vec4(vec3(fragColor), 1.5f);
// Dividing refrProb by 2 just for heuristic. Want more phong to show through.
@@ -90,6 +102,6 @@ void main() {
// 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));
-
- //fragColor = vec4(vec3(normal_worldSpace), 1.f);
+// fragColor = vec4(normal_worldSpace[0], 0, normal_worldSpace[1], 1.f);
+// fragColor = diffuse;
}