From e539092b4b55df8b55643d3c4783968e1d6e1ad1 Mon Sep 17 00:00:00 2001 From: Pieter-Jan Briers Date: Thu, 11 Mar 2021 19:04:21 +0100 Subject: [PATCH] Fix shader problems on GLES2 --- Resources/Prototypes/Shaders/shaders.yml | 11 ++++++++- .../Shaders/colored_screen_border.swsl | 6 ++--- .../Shaders/gradient_circle_mask.swsl | 4 ++-- Resources/Textures/Shaders/singularity.swsl | 24 +++++++++---------- Resources/Textures/Shaders/texture.swsl | 18 +++++++------- 5 files changed, 36 insertions(+), 27 deletions(-) diff --git a/Resources/Prototypes/Shaders/shaders.yml b/Resources/Prototypes/Shaders/shaders.yml index 0c0919abe7..a26a7c9c02 100644 --- a/Resources/Prototypes/Shaders/shaders.yml +++ b/Resources/Prototypes/Shaders/shaders.yml @@ -7,7 +7,7 @@ id: GradientCircleMask kind: source path: "/Textures/Shaders/gradient_circle_mask.swsl" - + - type: shader id: ColoredScreenBorder kind: source @@ -22,8 +22,17 @@ id: Singularity kind: source path: "/Textures/Shaders/singularity.swsl" + params: + positionInput: 0,0 + falloff: 5 + intensity: 5 - type: shader id: Texture kind: source path: "/Textures/Shaders/texture.swsl" + params: + positionInput: 0, 0 + pixelSize: 32, 32 + alphaCutoff: 0 + removeTransparency: false diff --git a/Resources/Textures/Shaders/colored_screen_border.swsl b/Resources/Textures/Shaders/colored_screen_border.swsl index e1c57f01a2..1b00fc1ed6 100644 --- a/Resources/Textures/Shaders/colored_screen_border.swsl +++ b/Resources/Textures/Shaders/colored_screen_border.swsl @@ -1,7 +1,7 @@ //Creates a border on the edges of the screen of the specified color and of the specified size (no uniforms yet cause I'm lazy) -const highp vec4 borderColor = vec4(230.0, 0.0, 0.0, 1.0); -const highp float borderSize = 30; //Pixel size of border +const highp vec4 borderColor = vec4(230.0, 0.0, 0.0, 1.0); +const highp float borderSize = 30.0; //Pixel size of border void fragment() { highp vec2 pixelSize = vec2(1.0/SCREEN_PIXEL_SIZE.x, 1.0/SCREEN_PIXEL_SIZE.y); @@ -18,4 +18,4 @@ void fragment() { if(smallestLength <= borderSize){ COLOR = vec4(borderColor.r, borderColor.g, borderColor.b, abs((1.0-(smallestLength/borderSize))*(abs(sin(TIME))*0.8+0.2))); } -} \ No newline at end of file +} diff --git a/Resources/Textures/Shaders/gradient_circle_mask.swsl b/Resources/Textures/Shaders/gradient_circle_mask.swsl index a785017ee4..23563f1cc4 100644 --- a/Resources/Textures/Shaders/gradient_circle_mask.swsl +++ b/Resources/Textures/Shaders/gradient_circle_mask.swsl @@ -3,7 +3,7 @@ light_mode unshaded; -const highp float darknessAlphaInner = 0.6; +const highp float darknessAlphaInner = 0.6; const highp float innerCircleRadius = 40.0; //Note: this is in pixels const highp float outerCircleRadius = 80.0; @@ -19,7 +19,7 @@ void fragment() { } else{ highp float intensity = (distance-innerCircleRadius)/(outerCircleRadius-innerCircleRadius); - COLOR = vec4(0.0, 0.0, 0.0, (1-intensity)*darknessAlphaInner + intensity); + COLOR = vec4(0.0, 0.0, 0.0, (1.0-intensity)*darknessAlphaInner + intensity); } } diff --git a/Resources/Textures/Shaders/singularity.swsl b/Resources/Textures/Shaders/singularity.swsl index 046df1afd0..af51376f26 100644 --- a/Resources/Textures/Shaders/singularity.swsl +++ b/Resources/Textures/Shaders/singularity.swsl @@ -1,32 +1,32 @@ //Gravitational lensing effect. Edited from https://unionassets.com/blog/the-effect-of-the-gravitational-lens-195 to be Clyde based (based on what) uniform sampler2D SCREEN_TEXTURE; -uniform highp vec2 positionInput = vec2(0,0); -uniform highp float falloff = 5.0; -uniform highp float intensity = 5.0; +uniform highp vec2 positionInput; +uniform highp float falloff; +uniform highp float intensity; void fragment() { - float distanceToCenter = length(FRAGCOORD.xy-positionInput); + highp float distanceToCenter = length(FRAGCOORD.xy-positionInput); - vec2 finalCoords = FRAGCOORD.xy - positionInput; - highp float deformation = (pow(intensity, 2)*500) / pow(distanceToCenter, pow(falloff, 0.5)); + highp vec2 finalCoords = FRAGCOORD.xy - positionInput; + highp float deformation = (pow(intensity, 2.0)*500.0) / pow(distanceToCenter, pow(falloff, 0.5)); if(deformation > 0.8) //Edit this for inward effect - deformation = pow(deformation, 0.3); + deformation = pow(deformation, 0.3); if(deformation > 0.001){ - finalCoords *= 1-deformation; //Change this to 1+deformation for inward effect + finalCoords *= 1.0-deformation; //Change this to 1+deformation for inward effect finalCoords += positionInput; //float darkenCircleSize = 600; //Calculate optional darkening effect (darker the closer we are to the center of the singularity) //float alph = (distanceToCenter-30)/(darkenCircleSize-30); //float darkening = 0.9-(alph*0.9); - + //Darkening effect optional (Darker the closer you are to the center) //COLOR = mix(texture(SCREEN_TEXTURE, finalCoords*SCREEN_PIXEL_SIZE), vec4(0.0, 0.0, 0.0, 1.0), darkening); - COLOR = texture(SCREEN_TEXTURE, finalCoords*SCREEN_PIXEL_SIZE); + COLOR = zTextureSpec(SCREEN_TEXTURE, finalCoords*SCREEN_PIXEL_SIZE); } else{ - COLOR = texture(SCREEN_TEXTURE, FRAGCOORD.xy*SCREEN_PIXEL_SIZE); + COLOR = zTextureSpec(SCREEN_TEXTURE, FRAGCOORD.xy*SCREEN_PIXEL_SIZE); } -} \ No newline at end of file +} diff --git a/Resources/Textures/Shaders/texture.swsl b/Resources/Textures/Shaders/texture.swsl index f92733058f..a44924b819 100644 --- a/Resources/Textures/Shaders/texture.swsl +++ b/Resources/Textures/Shaders/texture.swsl @@ -3,21 +3,21 @@ //Currently does not work with AtlasTextures, going to need some work. uniform sampler2D tex; -uniform highp vec2 positionInput = vec2(0,0); -uniform highp vec2 pixelSize = vec2(32, 32); -uniform highp float alphaCutoff = 0.0; -uniform bool removeTransparency = false; +uniform highp vec2 positionInput; +uniform highp vec2 pixelSize; +uniform highp float alphaCutoff; +uniform bool removeTransparency; void fragment() { - float pixelLength = pixelSize.x*2; - float halvedLength = pixelLength/2; + highp float pixelLength = pixelSize.x*2.0; + highp float halvedLength = pixelLength/2.0; if(FRAGCOORD.x > positionInput.x - halvedLength && FRAGCOORD.x < positionInput.x + halvedLength && FRAGCOORD.y > positionInput.y - halvedLength && FRAGCOORD.y < positionInput.y + halvedLength){ - vec2 finalCoords = (FRAGCOORD.xy-positionInput+(pixelLength/2))/pixelLength; - vec4 color = texture(tex, finalCoords); + highp vec2 finalCoords = (FRAGCOORD.xy-positionInput+(pixelLength/2.0))/pixelLength; + highp vec4 color = texture2D(tex, finalCoords); if(color.a > alphaCutoff){ if(removeTransparency) color.a = 1.0; COLOR = color; } } -} \ No newline at end of file +}