diff --git a/leenkx/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl b/leenkx/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl index 52c6176..3af7411 100644 --- a/leenkx/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl +++ b/leenkx/Shaders/ssrefr_pass/ssrefr_pass.frag.glsl @@ -1,5 +1,5 @@ //https://lettier.github.io/3d-game-shaders-for-beginners/screen-space-refraction.html -//Implemented by Yvain Douard. +//Implemented by Yvain Douard an 1k8. #version 450 @@ -64,7 +64,7 @@ vec4 rayCast(vec3 dir) { ddepth = getDeltaDepth(hitCoord); if (ddepth > 0.0) return binarySearch(dir); } - return vec4(getProjectedCoord(hitCoord), 0.0, 1.0); + return vec4(texCoord, 0.0, 1.0); } void main() { @@ -72,10 +72,11 @@ void main() { float roughness = g0.z; vec4 gr = textureLod(gbuffer_refraction, texCoord, 0.0); float ior = gr.x; - float opac = gr.y; + float opac = 1.0 - gr.y; float d = textureLod(gbufferD, texCoord, 0.0).r * 2.0 - 1.0; if (d == 0.0 || d == 1.0 || opac == 1.0 || ior == 1.0) { fragColor.rgb = textureLod(tex1, texCoord, 0.0).rgb; + fragColor.a = opac; return; } vec2 enc = g0.rg; @@ -86,7 +87,7 @@ void main() { vec3 viewNormal = V3 * n; vec3 viewPos = getPosView(viewRay, d, cameraProj); - vec3 refracted = refract(viewPos, viewNormal, 1.0 / ior); + vec3 refracted = refract(normalize(viewPos), viewNormal, 1.0 / ior); hitCoord = viewPos; vec3 dir = refracted * (1.0 - rand(texCoord) * ss_refractionJitter * roughness) * 2.0; @@ -98,9 +99,12 @@ void main() { clamp(-refracted.z, 0.0, 1.0) * clamp((length(viewPos - hitCoord)), 0.0, 1.0) * coords.w; intensity = clamp(intensity, 0.0, 1.0); - vec3 refractionCol = textureLod(tex1, coords.xy, 0.0).rgb; - refractionCol *= intensity; - vec3 color = textureLod(tex, texCoord.xy, 0.0).rgb; + vec4 refractionCol = textureLod(tex1, coords.xy, 0.0).rgba; + refractionCol.a = opac; + //refractionCol *= intensity; + vec4 color = textureLod(tex, texCoord.xy, 0.0).rgba; + color.a = opac; - fragColor.rgb = mix(refractionCol, color, opac); + fragColor.rgba = mix(refractionCol, color, opac); + fragColor.a = opac; }