diff --git a/core/src/main/resources/shaders/fog/fog.frag b/core/src/main/resources/shaders/fog/fog.frag index 8e9f0767a..04eb3f7c1 100644 --- a/core/src/main/resources/shaders/fog/fog.frag +++ b/core/src/main/resources/shaders/fog/fog.frag @@ -42,23 +42,14 @@ float mixFogThickness(float near, float far, float height); // ========================================================= -// Puts steps in a float -// EG. setting stepSize to 4 then this would be the result of this function -// In: 0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, ..., 1.1, 1.2, 1.3 -// Out: 0.0, 0.0, 0.0, 0.25, 0.25, 0.5, 0.5, ..., 1.0, 1.0, 1.25 -float quantize(float val, int stepSize) { - return floor(val*stepSize)/stepSize; +const vec3 MAGIC = vec3(0.06711056, 0.00583715, 52.9829189); + +float InterleavedGradientNoise(const in vec2 pixel) { + float x = dot(pixel, MAGIC.xy); + return fract(MAGIC.z * fract(x)); } -// The modulus function dosnt exist in GLSL so I made my own -// To speed up the mod function, this only accepts full numbers for y -float mod(float x, int y) { - return x - y * floor(x/y); -} - - -vec3 calcViewPosition(float fragmentDepth) -{ +vec3 calcViewPosition(float fragmentDepth) { vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0); ndc.xyz = ndc.xyz * 2.0 - 1.0; @@ -76,13 +67,12 @@ void main() { float vertexYPos = 100.0f; float fragmentDepth = texture(gDepthMap, TexCoord).r; + fragColor = vec4(fogColor.rgb, 0.0); // a fragment depth of "1" means the fragment wasn't drawn to, // we only want to apply Fog to LODs, not to the sky outside the LODs - if (fragmentDepth < 1) - { - if (fullFogMode == 0) - { + if (fragmentDepth < 1.0) { + if (fullFogMode == 0) { // render fog based on distance from the camera vec3 vertexWorldPos = calcViewPosition(fragmentDepth); @@ -94,17 +84,16 @@ void main() float farFogThickness = getFarFogThickness(farDist); float heightFogThickness = getHeightFogThickness(heightDist); float mixedFogThickness = mixFogThickness(nearFogThickness, farFogThickness, heightFogThickness); - mixedFogThickness = clamp(mixedFogThickness, 0.0, 1.0); + fragColor.a = clamp(mixedFogThickness, 0.0, 1.0); - fragColor = vec4(fogColor.rgb, mixedFogThickness); + float dither = InterleavedGradientNoise(gl_FragCoord.xy) - 0.5; + fragColor.a += dither / 255.0; } - else if (fullFogMode == 1) - { + else if (fullFogMode == 1) { // render everything with the fog color - fragColor = vec4(fogColor.rgb, 1.0); + fragColor.a = 1.0; } - else - { + else { // test code. // this can be fired by manually changing the fullFogMode to a (normally) @@ -112,19 +101,13 @@ void main() // a uniform we don't have to worry about GLSL optimizing away different // options when testing, causing a bunch of headaches if we just want to render the screen red. - float depthValue = texture(gDepthMap, TexCoord).r; - fragColor = vec4(vec3(depthValue), 1.0); // Convert depth value to grayscale color + float depthValue = textureLod(gDepthMap, TexCoord, 0).r; + fragColor.rgb = vec3(depthValue); // Convert depth value to grayscale color + fragColor.a = 1.0; } } - else - { - // every pixel needs to be set to something, otherwise the pixel may be undefined by some drivers (specifically Intel) - fragColor = vec4(0.0, 0.0, 0.0, 0.0); - } } - - // Are these still needed? float linearFog(float x, float fogStart, float fogLength, float fogMin, float fogRange) { x = clamp((x-fogStart)/fogLength, 0.0, 1.0); @@ -132,13 +115,15 @@ float linearFog(float x, float fogStart, float fogLength, float fogMin, float fo } float exponentialFog(float x, float fogStart, float fogLength, -float fogMin, float fogRange, float fogDensity) { + float fogMin, float fogRange, float fogDensity) +{ x = max((x-fogStart)/fogLength, 0.0) * fogDensity; return fogMin + fogRange - fogRange/exp(x); } float exponentialSquaredFog(float x, float fogStart, float fogLength, -float fogMin, float fogRange, float fogDensity) { + float fogMin, float fogRange, float fogDensity) +{ x = max((x-fogStart)/fogLength, 0.0) * fogDensity; return fogMin + fogRange - fogRange/exp(x*x); -} \ No newline at end of file +} diff --git a/core/src/main/resources/shaders/ssao/ao.frag b/core/src/main/resources/shaders/ssao/ao.frag index b23f6c901..abd315fdb 100644 --- a/core/src/main/resources/shaders/ssao/ao.frag +++ b/core/src/main/resources/shaders/ssao/ao.frag @@ -13,7 +13,7 @@ uniform mat4 gProj; uniform mat4 gInvProj; const float MIN_LIGHT = 0.6; -const float SAMPLE_BIAS = 0.5; +const float SAMPLE_BIAS = 0.6; const int MAX_KERNEL_SIZE = 32; const float INV_MAX_KERNEL_SIZE_F = 1.0 / float(MAX_KERNEL_SIZE); uniform vec3 gKernel[MAX_KERNEL_SIZE]; @@ -60,7 +60,7 @@ void main() { float occlusion_factor = 0.0; for (int i = 0; i < MAX_KERNEL_SIZE; i++) { vec3 samplePos = TBN * gKernel[i]; - samplePos *= sign(dot(samplePos, viewNormal)); + //samplePos *= sign(dot(samplePos, viewNormal)); samplePos = viewPos + samplePos * gSampleRad; vec4 sampleNdcPos = gProj * vec4(samplePos + viewPos, 1.0);