diff --git a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java index 305c7fe34..ce357c140 100644 --- a/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java +++ b/core/src/main/java/com/seibel/distanthorizons/core/render/renderer/shaders/SSAOShader.java @@ -46,8 +46,7 @@ public class SSAOShader extends AbstractShaderRenderer MC_RENDER.getTargetFrameBufferViewportWidth() / (float) MC_RENDER.getTargetFrameBufferViewportHeight(), RenderUtil.getNearClipPlaneDistanceInBlocks(partialTicks), (float) ((RenderUtil.getFarClipPlaneDistanceInBlocks() + LodUtil.REGION_WIDTH) * Math.sqrt(2))); - - + this.shader.setUniform(this.shader.getUniformLocation("gProj"), perspective); this.shader.setUniform(this.shader.getUniformLocation("gSampleRad"), 3.0f); this.shader.setUniform(this.shader.getUniformLocation("gFactor"), 0.8f); diff --git a/core/src/main/resources/shaders/curve.vert b/core/src/main/resources/shaders/curve.vert index a5ea716a2..5228831c7 100644 --- a/core/src/main/resources/shaders/curve.vert +++ b/core/src/main/resources/shaders/curve.vert @@ -29,7 +29,7 @@ uniform float earthRadius; */ void main() { - vPos = vec4(vPosition.x, vPosition.y, vPosition.z, vPosition.w); // This is so it can be passed to the fragment shader + vPos = vPosition.x; // This is so it can be passed to the fragment shader vertexWorldPos = vPosition.xyz + modelOffset; @@ -52,36 +52,35 @@ void main() vertexWorldPos.y += my; vertexWorldPos.z += mz; - // Old (disabled) vertex transformation logic - Leetom #if 0 + // Old (disabled) vertex transformation logic - Leetom - // Calculate the vertex pos due to curvature of the earth - // We use spherical coordinates to calculate the vertex position - if(vertexWorldPos.x == 0.0 && vertexWorldPos.z == 0.0) - { - // In the center. No curvature needed - } - else - { - float theta = atan(vertexWorldPos.z, vertexWorldPos.x); // in radians (-pi, pi) - float trueY = earthRadius + vertexWorldPos.y; // true Y position, or height - float phi = sqrt(vertexWorldPos.z * vertexWorldPos.z + vertexWorldPos.x * vertexWorldPos.x) / trueY; - // Convert spherical coordinates to cartesian coordinates - vertexWorldPos.x = trueY * sin(phi) * cos(theta); - vertexWorldPos.z = trueY * sin(phi) * sin(theta); - vertexWorldPos.y = trueY * cos(phi) - earthRadius; - } + // Calculate the vertex pos due to curvature of the earth + // We use spherical coordinates to calculate the vertex position + //if (vertexWorldPos.x == 0.0 && vertexWorldPos.z == 0.0) + //{ + // // In the center. No curvature needed + //} + //else + //{ + float theta = atan(vertexWorldPos.z, vertexWorldPos.x); // in radians (-pi, pi) + float trueY = earthRadius + vertexWorldPos.y; // true Y position, or height + float phi = sqrt(vertexWorldPos.z * vertexWorldPos.z + vertexWorldPos.x * vertexWorldPos.x) / trueY; + // Convert spherical coordinates to cartesian coordinates + vertexWorldPos.x = trueY * sin(phi) * cos(theta); + vertexWorldPos.z = trueY * sin(phi) * sin(theta); + vertexWorldPos.y = trueY * cos(phi) - earthRadius; + //} #else - // new vertex transformation logic - stduhpf + // new vertex transformation logic - stduhpf - float localRadius = earthRadius + vertexYPos;// vertexWorldPos.y + cameraPosition.y - Center_Y; + float localRadius = earthRadius + vertexYPos;// vertexWorldPos.y + cameraPosition.y - Center_Y; - float phi = length(vertexWorldPos.xz) / localRadius; - - vertexWorldPos.y += (cos(phi) - 1.) * localRadius; - vertexWorldPos.xz = vertexWorldPos.xz * sin(phi) / phi; + float phi = length(vertexWorldPos.xz) / localRadius; + vertexWorldPos.y += (cos(phi) - 1.0) * localRadius; + vertexWorldPos.xz = vertexWorldPos.xz * sin(phi) / phi; #endif uint lights = meta & 0xFFu; diff --git a/core/src/main/resources/shaders/flat_shaded.frag b/core/src/main/resources/shaders/flat_shaded.frag index f3bbdedb1..28109a009 100644 --- a/core/src/main/resources/shaders/flat_shaded.frag +++ b/core/src/main/resources/shaders/flat_shaded.frag @@ -18,8 +18,9 @@ uniform int noiseDropoff; // method definitions float fade(float value, float start, float end) { - return (clamp(value,start,end)-start)/(end-start); + return (clamp(value, start, end) - start) / (end - start); } + // The random functions for diffrent dimentions float rand(float co) { return fract(sin(co*(91.3458)) * 47453.5453); } float rand(vec2 co){ return fract(sin(dot(co.xy ,vec2(12.9898,78.233))) * 43758.5453); } @@ -50,6 +51,7 @@ vec3 RGB2HSV(vec3 c) { float e = 1.0e-10; return vec3(abs(q.z + (q.w - q.y) / (6.0 * d + e)), d / (q.x + e), q.x); } + vec3 HSV2RGB(vec3 c) { vec4 K = vec4(1.0, 2.0 / 3.0, 1.0 / 3.0, 3.0); vec3 p = abs(fract(c.xxx + K.xyz) * 6.0 - K.www); @@ -74,15 +76,10 @@ void main() if (noiseEnabled) { vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz))); // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable - vec3 fixedVPos = vec3( - vPos.x - vertexNormal.x * 0.001, - vPos.y - vertexNormal.y * 0.001, - vPos.z - vertexNormal.z * 0.001 - ); + vec3 fixedVPos = vPos.xyz - vertexNormal * 0.001; - - float noiseAmplification = noiseIntensity / 100; - noiseAmplification = (-1 * pow(2*((fragColor.x + fragColor.y + fragColor.z) / 3) - 1, 2) + 1) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1 + float noiseAmplification = noiseIntensity * 0.01; + noiseAmplification = (-1.0 * pow(2.0*((fragColor.x + fragColor.y + fragColor.z) / 3.0) - 1.0, 2.0) + 1.0) * noiseAmplification; // Lessen the effect on depending on how dark the object is, equasion for this is -(2x-1)^{2}+1 noiseAmplification *= fragColor.w; // The effect would lessen on transparent objects // Random value for each position @@ -91,30 +88,20 @@ void main() quantize(fixedVPos.y, noiseSteps), quantize(fixedVPos.z, noiseSteps) )) - * 2. * noiseAmplification - noiseAmplification; + * 2.0 * noiseAmplification - noiseAmplification; // Modifies the color // A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color - vec3 newCol = fragColor.rgb + (vec3(1.0) - fragColor.rgb) * randomValue; + vec3 newCol = fragColor.rgb + (1.0 - fragColor.rgb) * randomValue; // Clamps it and turns it back into a vec4 if (noiseDropoff == 0) - fragColor = vec4( - clamp(newCol.r, 0., 1.), - clamp(newCol.g, 0., 1.), - clamp(newCol.b, 0., 1.), - fragColor.w - ); + fragColor = vec4(clamp(newCol.rgb, 0.0, 1.0), fragColor.w); else fragColor = mix( - vec4( - clamp(newCol.r, 0., 1.), - clamp(newCol.g, 0., 1.), - clamp(newCol.b, 0., 1.), - fragColor.w - ), fragColor, - clamp(length(vertexWorldPos) / noiseDropoff, 0., 1.) // The further away it gets, the less noise gets applied + vec4(clamp(newCol.rgb, 0.0, 1.0), fragColor.w), fragColor, + min(length(vertexWorldPos) / noiseDropoff, 1.0) // The further away it gets, the less noise gets applied ); // For testing diff --git a/core/src/main/resources/shaders/fog/fog.frag b/core/src/main/resources/shaders/fog/fog.frag index 9ec282886..a9f317700 100644 --- a/core/src/main/resources/shaders/fog/fog.frag +++ b/core/src/main/resources/shaders/fog/fog.frag @@ -59,16 +59,12 @@ float mod(float x, int y) { vec3 calcViewPosition(float fragmentDepth) { - vec4 ndc = vec4( - TexCoord.x * 2.0 - 1.0, - TexCoord.y * 2.0 - 1.0, - fragmentDepth * 2.0 - 1.0, - 1.0 - ); + vec4 ndc = vec4(TexCoord.xy, fragmentDepth, 1.0); + ndc.xyz = ndc.xyz * 2.0 - 1.0; + // TODO: This inverse() should be moved CPU side vec4 eyeCoord = inverse(gMvmProj) * ndc; - vec3 cameraPos = eyeCoord.xyz / eyeCoord.w; - return cameraPos; + return eyeCoord.xyz / eyeCoord.w; } /** @@ -84,8 +80,7 @@ void main() // 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 - // FIXME: This bit of code causes problems on intel integrated graphics - if (fragmentDepth != -420.0) // Should be `1.0`, but set to `-420.0` both so that the compiler doesnt mess with rest of the code, and it always returns true + if (fragmentDepth < 1) { if (fullFogMode == 0) { @@ -99,17 +94,15 @@ void main() float nearFogThickness = getNearFogThickness(horizontalDist); float farFogThickness = getFarFogThickness(farDist); float heightFogThickness = getHeightFogThickness(heightDist); - float mixedFogThickness = - clamp( - mixFogThickness(nearFogThickness, farFogThickness, heightFogThickness) - , 0.0, 1.0); + float mixedFogThickness = mixFogThickness(nearFogThickness, farFogThickness, heightFogThickness); + mixedFogThickness = clamp(mixedFogThickness, 0.0, 1.0); - fragColor = vec4(fogColor.r, fogColor.g, fogColor.b, mixedFogThickness); + fragColor = vec4(fogColor.rgb, mixedFogThickness); } else if (fullFogMode == 1) { // render everything with the fog color - fragColor = vec4(fogColor.r, fogColor.g, fogColor.b, 1.0); + fragColor = vec4(fogColor.rgb, 1.0); } else { @@ -124,6 +117,11 @@ void main() fragColor = vec4(vec3(depthValue), 1.0); // Convert depth value to grayscale color } } + 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); + } } diff --git a/core/src/main/resources/shaders/noise/noise.frag b/core/src/main/resources/shaders/noise/noise.frag index 4eeff968c..9ae668cbe 100644 --- a/core/src/main/resources/shaders/noise/noise.frag +++ b/core/src/main/resources/shaders/noise/noise.frag @@ -26,6 +26,10 @@ float quantize(float val, int stepSize) { return floor(val*stepSize)/stepSize; } +vec3 quantize(vec3 val, int stepSize) { + return floor(val*stepSize)/stepSize; +} + // 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) { @@ -44,11 +48,7 @@ float mod(float x, int y) { void main() { // This bit of code is required to fix the vertex position problem cus of floats in the verted world position varuable vec3 vertexNormal = normalize(cross(dFdx(vPos.xyz), dFdy(vPos.xyz))); - vec3 fixedVPos = vec3( - vPos.x - vertexNormal.x * 0.001, - vPos.y - vertexNormal.y * 0.001, - vPos.z - vertexNormal.z * 0.001 - ); + vec3 fixedVPos = vPos.xyz - vertexNormal * 0.001; float noiseAmplification = noiseIntensity / 100; @@ -56,29 +56,20 @@ void main() { noiseAmplification *= vertexColor.w; // The effect would lessen on transparent objects // Random value for each position - float randomValue = rand(vec3( - quantize(fixedVPos.x, noiseSteps), - quantize(fixedVPos.y, noiseSteps), - quantize(fixedVPos.z, noiseSteps) - )) - * 2. * noiseAmplification - noiseAmplification; + float randomValue = rand(quantize(fixedVPos.xyz, noiseSteps)) + * 2.0 * noiseAmplification - noiseAmplification; // Modifies the color // A value of 0 on the randomValue will result in the original color, while a value of 1 will result in a fully bright color - vec3 newCol = (vec3(1.0) - vertexColor.rgb) * randomValue; + vec3 newCol = (1.0 - vertexColor.rgb) * randomValue; // Clamps it and turns it back into a vec4 - fragColor = vec4( - clamp(newCol.r, 0., 1.), - clamp(newCol.g, 0., 1.), - clamp(newCol.b, 0., 1.), - clamp(length(vertexWorldPos) * distanceScale * noiseDropoff, 0., 1.) // The further away it gets, the less noise gets applied - ); - fragColor = vec4( - 0f, 0f, 0f, - randomValue // The further away it gets, the less noise gets applied - ); + float distA = length(vertexWorldPos) * distanceScale * noiseDropoff; + fragColor = clamp(vec4(newCol.rgb, distA), 0.0, 1.0); // The further away it gets, the less noise gets applied + + // The further away it gets, the less noise gets applied + fragColor = vec4(0.0, 0.0, 0.0, randomValue); // For testing // if (vertexColor.r != 69420.) { diff --git a/core/src/main/resources/shaders/ssao/ao.frag b/core/src/main/resources/shaders/ssao/ao.frag index 15f648764..33be6a37d 100644 --- a/core/src/main/resources/shaders/ssao/ao.frag +++ b/core/src/main/resources/shaders/ssao/ao.frag @@ -35,22 +35,19 @@ void main() vec3 viewPos = calcViewPosition(TexCoord); vec3 viewNormal = normalize(cross(dFdy(viewPos.xyz), dFdx(viewPos.xyz)) * -1.0); - vec3 randomVec = vec3( - 0.0, - -1.0, - 0.0 - ); + vec3 randomVec = vec3(0.0, -1.0, 0.0); vec3 tangent = normalize(randomVec - viewNormal * dot(randomVec, viewNormal)); vec3 bitangent = cross(viewNormal, tangent); mat3 TBN = mat3(tangent, bitangent, viewNormal); + float occlusion_factor = 0.0; - for (int i = 0; i < MAX_KERNEL_SIZE; i++) { + for (int i = 0; i < MAX_KERNEL_SIZE; i++) + { vec3 samplePos = vec3(0.0) + (TBN * gKernel[i]); samplePos = viewPos + samplePos * gSampleRad; - vec4 offset = vec4(samplePos, 1.0); - offset = gProj * offset; + vec4 offset = gProj * vec4(samplePos + viewPos, 1.0); offset.xy /= offset.w; offset.xy = offset.xy * HALF_2 + HALF_2; diff --git a/core/src/main/resources/shaders/ssao/apply-frag.frag b/core/src/main/resources/shaders/ssao/apply-frag.frag index 03bb09f18..534306c50 100644 --- a/core/src/main/resources/shaders/ssao/apply-frag.frag +++ b/core/src/main/resources/shaders/ssao/apply-frag.frag @@ -13,9 +13,13 @@ void main() float fragmentDepth = texture(gDepthMap, TexCoord).r; // a fragment depth of "1" means the fragment wasn't drawn to, // we only want to apply SSAO to LODs, not to the sky outside the LODs - // FIXME: This bit of code causes problems on intel integrated graphics - if (fragmentDepth != -420.0) // Should be `1.0`, but set to `-420.0` both so that the compiler doesnt mess with rest of the code, and it always returns true + if (fragmentDepth < 1) { - fragColor = vec4(0.0, 0.0, 0.0, 1-texture(gSSAOMap, TexCoord).r); + fragColor = vec4(0.0, 0.0, 0.0, 1-texture(gSSAOMap, TexCoord).r); + } + 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); } } diff --git a/core/src/main/resources/shaders/standard.vert b/core/src/main/resources/shaders/standard.vert index 364bd1722..c7e446cf8 100644 --- a/core/src/main/resources/shaders/standard.vert +++ b/core/src/main/resources/shaders/standard.vert @@ -29,7 +29,7 @@ uniform float mircoOffset; */ void main() { - vPos = vec4(vPosition.x, vPosition.y, vPosition.z, vPosition.w); // This is so it can be passed to the fragment shader + vPos = vPosition; // This is so it can be passed to the fragment shader vertexWorldPos = vPosition.xyz + modelOffset; @@ -54,6 +54,7 @@ void main() float light2 = (mod(float(lights), 16.0)+0.5) / 16.0; float light = (float(lights/16u)+0.5) / 16.0; vertexColor = vec4(texture(lightMap, vec2(light, light2)).xyz, 1.0); + if (!whiteWorld) { vertexColor *= color;