Fix shader problems on GLES2

This commit is contained in:
Pieter-Jan Briers
2021-03-11 19:04:21 +01:00
parent 063d1c71b3
commit e539092b4b
5 changed files with 36 additions and 27 deletions

View File

@@ -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

View File

@@ -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)));
}
}
}

View File

@@ -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);
}
}

View File

@@ -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);
}
}
}

View File

@@ -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;
}
}
}
}