diff options
author | Sebastian Park <SebPark03@gmail.com> | 2024-04-24 03:29:09 -0400 |
---|---|---|
committer | Sebastian Park <SebPark03@gmail.com> | 2024-04-24 03:29:09 -0400 |
commit | ef8abb44ca5cbf62a24b265aedc62f1348ae8091 (patch) | |
tree | 51dec7207123017d2012722d7acdfdb7ba2857ae /resources | |
parent | d2356bae7beb968ad333f3baf21b4830d647f8ce (diff) |
ADD MULTIPLE TEXTURES AFTER MANY FREAKING HOURS.
Diffstat (limited to 'resources')
-rwxr-xr-x | resources/shaders/shader.frag | 11 | ||||
-rwxr-xr-x | resources/shaders/shader.vert | 14 |
2 files changed, 25 insertions, 0 deletions
diff --git a/resources/shaders/shader.frag b/resources/shaders/shader.frag index 80a65a2..0697359 100755 --- a/resources/shaders/shader.frag +++ b/resources/shaders/shader.frag @@ -5,6 +5,7 @@ in vec3 normal_cameraSpace; in vec3 camera_worldSpace; in vec3 normal_worldSpace; in vec3 pos; +in vec3 reflPos; in vec3 refrPos; in float refrProb; in vec2 uv; @@ -18,12 +19,16 @@ uniform float red = 1.0; uniform float green = 1.0; uniform float blue = 1.0; uniform float alpha = 1.0; +//layout(binding = 0) uniform sampler2D groundSampler; +//layout(binding = 1) uniform sampler2D skySampler; uniform sampler2D groundSampler; uniform sampler2D skySampler; uniform vec2 widthBounds; uniform vec2 lengthBounds; //uniform float test = 0; +// Random methods from https://gist.github.com/patriciogonzalezvivo/670c22f3966e662d2f83 + float rand(vec2 n) { return fract(sin(dot(n, vec2(12.9898, 4.1414))) * 43758.5453); } @@ -63,6 +68,8 @@ void main() { // fragColor = vec4(fragColor.x, 0.f, fragColor.z, 1.f); // fragColor = vec4(test, test, test, 1.f); vec2 refrUV = uvFromWorldPoint(refrPos); + vec2 reflUV = uvFromWorldPoint(reflPos); + float waterMurkiness = 0.002f; // TODO: Make uniform vec3 waterVolumeColor = vec3(red * 0.1f, green * 0.2f, blue * 0.2f); float murkDiffuse = 0.3f; @@ -79,6 +86,7 @@ void main() { vec4 transmissive = texture(groundSampler, vec2(refrUVBlurry)); vec4 murk = (vec4(waterVolumeColor * d * murkDiffuse + waterVolumeColor * murkAmbient, 1.0f)); + vec4 skyRefl = texture(skySampler, vec2(reflUV)); // refrProb *= beerAtt; fragColor = 0.75f * diffuse; // Diffuse @@ -87,6 +95,9 @@ void main() { fragColor = vec4(red * .2f, green * .2f, blue * .2f,1.f); fragColor += 1.f * specular; // Specular TODO: Pass multiplications as uniforms. fragColor = clamp(fragColor, 0.f, 1.f); // Clamp + fragColor += 0.2f * skyRefl * vec4(0.8f, 0.9f, 1.f, 1.f); + fragColor = clamp(fragColor, 0.f, 1.f); // Clamp + fragColor *= ((1 - refrProb) / 1.f); vec4 volumetric = beerAtt * transmissive; diff --git a/resources/shaders/shader.vert b/resources/shaders/shader.vert index 7a7dde5..e78ddc6 100755 --- a/resources/shaders/shader.vert +++ b/resources/shaders/shader.vert @@ -18,6 +18,7 @@ out vec3 normal_cameraSpace; out vec3 normal_worldSpace; out vec3 camera_worldSpace; out vec3 pos; +out vec3 reflPos; out vec3 refrPos; out float refrProb; out vec2 uv; @@ -53,6 +54,17 @@ vec4 getRefrPos() { } } +vec3 getReflPos() { + float depth = 5000.f; // TODO: Pass as uniform + vec3 w_o = normalize(pos - camera_worldSpace); + vec3 reflectedRay = 2 * dot(-w_o, normal_worldSpace) * normal_worldSpace + w_o; + + float dist = depth - position.y; + float depthScale = dist / reflectedRay.y; + vec3 skyContactPoint = (reflectedRay * depthScale) + position; + return skyContactPoint; +} + void main() { // float depth = -4.f; // float dist = position.y - depth; @@ -75,5 +87,7 @@ void main() { refrPos = vec3(refrPos_and_prob); refrProb = clamp(refrPos_and_prob.w, 0.f, 1.f); + reflPos = getReflPos(); + gl_Position = proj * view * model * vec4(position, 1); } |