From 1be1f72f6c5ef69caaec90f7e42b0a5e6f43e4bf Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 21 Apr 2023 09:02:12 +0400 Subject: [PATCH] Improve shaders formatting --- files/shaders/compatibility/debug.vert | 5 ++-- .../compatibility/multiview_resolve.frag | 18 +++++------ .../compatibility/ripples_simulate.frag | 1 - .../compatibility/shadows_fragment.glsl | 13 ++++---- files/shaders/compatibility/sky.frag | 3 +- files/shaders/compatibility/water.frag | 4 +-- files/shaders/lib/particle/soft.glsl | 3 +- files/shaders/lib/view/depth.glsl | 8 ++--- files/shaders/lib/water/fresnel.glsl | 30 ++++++++++--------- 9 files changed, 43 insertions(+), 42 deletions(-) diff --git a/files/shaders/compatibility/debug.vert b/files/shaders/compatibility/debug.vert index 1f97cfc025..47d5337a66 100644 --- a/files/shaders/compatibility/debug.vert +++ b/files/shaders/compatibility/debug.vert @@ -5,8 +5,8 @@ uniform vec3 color; uniform vec3 trans; uniform vec3 scale; -uniform bool useNormalAsColor; -uniform bool useAdvancedShader = false; +uniform bool useNormalAsColor; +uniform bool useAdvancedShader = false; centroid varying vec4 passColor; varying vec3 vertexNormal; @@ -27,5 +27,4 @@ void main() vec3 colorOut = useNormalAsColor? gl_Normal.xyz : color; passColor = vec4(colorOut, 1.); } - } diff --git a/files/shaders/compatibility/multiview_resolve.frag b/files/shaders/compatibility/multiview_resolve.frag index 3655f1fa26..a77a3b35d1 100644 --- a/files/shaders/compatibility/multiview_resolve.frag +++ b/files/shaders/compatibility/multiview_resolve.frag @@ -6,13 +6,13 @@ uniform sampler2DArray lastShader; void main() { - int view = 0; - vec3 uvz = vec3(uv.x * 2., uv.y, 0); - if(uvz.x > 1.) - { - uvz.x -= 1.; - uvz.z = 1; - } - + int view = 0; + vec3 uvz = vec3(uv.x * 2., uv.y, 0); + if(uvz.x > 1.) + { + uvz.x -= 1.; + uvz.z = 1; + } + gl_FragColor = texture2DArray(lastShader, uvz); -} \ No newline at end of file +} diff --git a/files/shaders/compatibility/ripples_simulate.frag b/files/shaders/compatibility/ripples_simulate.frag index 8b19c3386c..f36cab5b40 100644 --- a/files/shaders/compatibility/ripples_simulate.frag +++ b/files/shaders/compatibility/ripples_simulate.frag @@ -27,7 +27,6 @@ void main() texture2D(imageIn, uv + vec2(0.0, -oneAndHalfOffset)).r ); - vec4 color = texture2D(imageIn, uv); gl_FragColor = applySprings(color, n, n2); diff --git a/files/shaders/compatibility/shadows_fragment.glsl b/files/shaders/compatibility/shadows_fragment.glsl index 6143709915..2945edff3d 100644 --- a/files/shaders/compatibility/shadows_fragment.glsl +++ b/files/shaders/compatibility/shadows_fragment.glsl @@ -35,7 +35,6 @@ float unshadowedLightRatio(float distance) { shadowing = min(shadow2DProj(shadowTexture@shadow_texture_unit_index, shadowSpaceCoords@shadow_texture_unit_index).r, shadowing); - doneShadows = all(lessThan(shadowXYZ, vec3(0.95, 0.95, 1.0))) && all(greaterThan(shadowXYZ, vec3(0.05, 0.05, 0.0))); #if @perspectiveShadowMaps doneShadows = doneShadows && all(lessThan(shadowRegionXYZ, vec3(1.0, 1.0, 1.0))) && all(greaterThan(shadowRegionXYZ.xy, vec2(-1.0, -1.0))); @@ -70,12 +69,12 @@ void applyShadowDebugOverlay() if (all(lessThan(shadowXYZ.xy, vec2(1.0, 1.0))) && all(greaterThan(shadowXYZ.xy, vec2(0.0, 0.0)))) { colourIndex = mod(@shadow_texture_unit_index.0, 3.0); - if (colourIndex < 1.0) - gl_FragData[0].x += 0.1; - else if (colourIndex < 2.0) - gl_FragData[0].y += 0.1; - else - gl_FragData[0].z += 0.1; + if (colourIndex < 1.0) + gl_FragData[0].x += 0.1; + else if (colourIndex < 2.0) + gl_FragData[0].y += 0.1; + else + gl_FragData[0].z += 0.1; doneOverlay = all(lessThan(shadowXYZ, vec3(0.95, 0.95, 1.0))) && all(greaterThan(shadowXYZ, vec3(0.05, 0.05, 0.0))); #if @perspectiveShadowMaps diff --git a/files/shaders/compatibility/sky.frag b/files/shaders/compatibility/sky.frag index 7c4ea561d2..1e1dfb71e4 100644 --- a/files/shaders/compatibility/sky.frag +++ b/files/shaders/compatibility/sky.frag @@ -79,7 +79,8 @@ void main() paintSun(color); else if (pass == PASS_SUNGLARE) paintSunglare(color); - else if (pass == PASS_SUNFLASH_QUERY) { + else if (pass == PASS_SUNFLASH_QUERY) + { processSunflashQuery(); return; } diff --git a/files/shaders/compatibility/water.frag b/files/shaders/compatibility/water.frag index 6db51106fd..83fb8a53e0 100644 --- a/files/shaders/compatibility/water.frag +++ b/files/shaders/compatibility/water.frag @@ -113,9 +113,9 @@ void main(void) vec4 rainRipple; if (rainIntensity > 0.01) - rainRipple = rainCombined(position.xy/1000.0, waterTimer) * clamp(rainIntensity, 0.0, 1.0); + rainRipple = rainCombined(position.xy/1000.0, waterTimer) * clamp(rainIntensity, 0.0, 1.0); else - rainRipple = vec4(0.0); + rainRipple = vec4(0.0); vec3 rippleAdd = rainRipple.xyz * 10.0; diff --git a/files/shaders/lib/particle/soft.glsl b/files/shaders/lib/particle/soft.glsl index f12ec4d9cc..c415d8402b 100644 --- a/files/shaders/lib/particle/soft.glsl +++ b/files/shaders/lib/particle/soft.glsl @@ -35,7 +35,8 @@ float calcSoftParticleFade( const float nearMult = 300.0; float viewBias = 1.0; - if (fade) { + if (fade) + { float VdotN = dot(viewDir, viewNormal); viewBias = abs(VdotN) * quickstep(euclidianDepth / nearMult) * (1.0 - pow(1.0 + VdotN, 1.3)); } diff --git a/files/shaders/lib/view/depth.glsl b/files/shaders/lib/view/depth.glsl index 7773c141de..79bea3fff9 100644 --- a/files/shaders/lib/view/depth.glsl +++ b/files/shaders/lib/view/depth.glsl @@ -4,11 +4,11 @@ float linearizeDepth(float depth, float near, float far) { #if @reverseZ - depth = 1.0 - depth; + depth = 1.0 - depth; #endif - float z_n = 2.0 * depth - 1.0; - depth = 2.0 * near * far / (far + near - z_n * (far - near)); - return depth; + float z_n = 2.0 * depth - 1.0; + depth = 2.0 * near * far / (far + near - z_n * (far - near)); + return depth; } float getLinearDepth(in float z, in float viewZ) diff --git a/files/shaders/lib/water/fresnel.glsl b/files/shaders/lib/water/fresnel.glsl index 929b027400..d9d02b6903 100644 --- a/files/shaders/lib/water/fresnel.glsl +++ b/files/shaders/lib/water/fresnel.glsl @@ -1,23 +1,25 @@ #ifndef LIB_WATER_FRESNEL #define LIB_WATER_FRESNEL -float fresnel_dielectric(vec3 Incoming, vec3 Normal, float eta) +float fresnel_dielectric(vec3 incoming, vec3 normal, float eta) { - float c = abs(dot(Incoming, Normal)); - float g = eta * eta - 1.0 + c * c; - float result; + float c = abs(dot(incoming, normal)); + float g = eta * eta - 1.0 + c * c; + float result; - if (g > 0.0) { - g = sqrt(g); - float A =(g - c)/(g + c); - float B =(c *(g + c)- 1.0)/(c *(g - c)+ 1.0); - result = 0.5 * A * A *(1.0 + B * B); - } - else { - result = 1.0; /* TIR (no refracted component) */ - } + if (g > 0.0) + { + g = sqrt(g); + float A =(g - c)/(g + c); + float B =(c *(g + c)- 1.0)/(c *(g - c)+ 1.0); + result = 0.5 * A * A *(1.0 + B * B); + } + else + { + result = 1.0; /* TIR (no refracted component) */ + } - return result; + return result; } #endif