Skip to content

Commit

Permalink
Graphics improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
cadyn committed Aug 31, 2022
1 parent 5db626f commit e841ab6
Show file tree
Hide file tree
Showing 12 changed files with 2,012 additions and 9 deletions.
12 changes: 11 additions & 1 deletion Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
[package]
name = "pong_multiplayer_rs"
version = "0.1.0"
version = "0.1.1"
edition = "2021"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html

[dependencies]
bevy = "0.8.0"
bevy_crt = "0.1.2"
bevy_internal = "0.8.0"
bevy_renet = "0.0.5"
bincode = "1.3.3"
Expand Down
63 changes: 63 additions & 0 deletions assets/shaders/crt-guest-advanced-hd/afterglow.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
#version 450

/*
Phosphor Afterglow Shader pass 0
Copyright (C) 2020 guest(r) - [email protected]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

//#pragma parameter internal_res " Internal Resolution" 1.0 1.0 8.0 0.10
#define internal_res 1.0
//#pragma parameter PR " Persistence Red" 0.32 0.0 0.50 0.01
#define PR 0.12
//#pragma parameter PG " Persistence Green" 0.32 0.0 0.50 0.01
#define PG 0.12
//#pragma parameter PB " Persistence Blue" 0.32 0.0 0.50 0.01
#define PB 0.12
//#pragma parameter AS " Afterglow Strength" 0.20 0.0 0.60 0.01
#define AS 0.20
//#pragma parameter sat " Afterglow saturation" 0.50 0.0 1.0 0.01
#define sat 0.50

#define COMPAT_TEXTURE(b,c,d) texture(sampler2D(b,c),d)

layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 1, binding = 0) uniform texture2D OriginalHistory0_texture;
layout(set = 1, binding = 1) uniform sampler OriginalHistory0;
layout(set = 1, binding = 2) uniform vec2 TextSize;
layout(set = 1, binding = 3) uniform texture2D AfterglowPassFeedback_texture;
layout(set = 1, binding = 4) uniform sampler AfterglowPassFeedback;

#define TEX0 vTexCoord


void main()
{
vec3 color = COMPAT_TEXTURE(OriginalHistory0_texture, OriginalHistory0, TEX0.xy).rgb;
vec3 accumulate = COMPAT_TEXTURE(AfterglowPassFeedback_texture, AfterglowPassFeedback, TEX0.xy).rgb;

float w = 1.0;
if ((color.r + color.g + color.b < (25.0/255.0))) { w = 0.0; }

vec3 result = mix( max(mix(color, accumulate, 0.49 + vec3(PR, PG, PB))- 2.0/255.0, 0.0), color, w);

FragColor = vec4(result,1.0);
//FragColor = vec4(clamp(accumulate + color,0.0,1.0), w);
//FragColor = COMPAT_TEXTURE(OriginalHistory0_texture, OriginalHistory0, TEX0.xy);
}
84 changes: 84 additions & 0 deletions assets/shaders/crt-guest-advanced-hd/bloom_horizontal.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#version 450

/*
Gaussian blur - horizontal pass, dynamic range, resizable
Copyright (C) 2021 guest(r) - [email protected]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/

//#pragma parameter bogus_glow "[ GLOW/BLOOM PASS SETTINGS ]:" 0.0 0.0 1.0 1.0

//#pragma parameter SIZEHB " H. Bloom/Halation/Glow Radius" 4.0 1.0 30.0 1.0
#define SIZEHB 4.0

//#pragma parameter SIGMA_HB " Horizontal Bloom/Halation/Glow Sigma" 1.0 0.25 15.0 0.05
#define SIGMA_HB 1.0

#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 1, binding = 0) uniform texture2D LinearizePass_texture;
layout(set = 1, binding = 1) uniform sampler LinearizePass;
layout(set = 1, binding = 2) uniform vec2 TextSize;

#define COMPAT_TEXTURE(c,d) texture(sampler2D(LinearizePass_texture,c),d)

float invsqrsigma = 1.0/(2.0*SIGMA_HB*SIGMA_HB);

float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}

void main()
{
vec2 invTextSize = 1 / TextSize;
vec4 OriginalSize = vec4(TextSize,invTextSize.x,invTextSize.y);
vec4 SourceSize1 = OriginalSize;
float f = fract(SourceSize1.x * vTexCoord.x);
f = 0.5 - f;
vec2 tex = floor(SourceSize1.xy * vTexCoord)*SourceSize1.zw + 0.5*SourceSize1.zw;
vec4 color = vec4(0.0);
vec2 dx = vec2(SourceSize1.z, 0.0);

float w;
float wsum = 0.0;
vec4 pixel;
float n = -SIZEHB;

do
{
pixel = COMPAT_TEXTURE(LinearizePass, tex + n*dx);
w = gaussian(n+f);
pixel.a = max(max(pixel.r, pixel.g),pixel.b);
pixel.a*=pixel.a*pixel.a;
color = color + w * pixel;
wsum = wsum + w;
n = n + 1.0;

} while (n <= SIZEHB);

color = color / wsum;

float lenadj = pow(length(color.rgb) / sqrt(3), 0.333333) * sqrt(3);

color = color * (lenadj/length(color.rgb));

FragColor = vec4(color.rgb, 1.0);
//FragColor = vec4(color.rgb, pow(color.a, 0.333333));
}
90 changes: 90 additions & 0 deletions assets/shaders/crt-guest-advanced-hd/bloom_vertical.frag
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#version 450

/*
Gaussian blur - vertical pass, dynamic range, resizable
Copyright (C) 2020 guest(r) - [email protected]
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/


//#pragma parameter SIZEVB " V. Bloom/Halation/Glow Radius" 4.0 1.0 30.0 1.0
#define SIZEVB 4.0

//#pragma parameter SIGMA_VB " Vertical Bloom/Halation/Glow Sigma" 1.0 0.25 15.0 0.05
#define SIGMA_VB 1.0

//#pragma parameter prescalex " Prescale-X Factor (for xBR...pre-shader...)" 1.0 1.0 5.0 0.25 // Joint parameter with main pass, values must match
#define prescalex 1.0

//#pragma parameter prescaley " Prescale-Y Factor (for xBR...pre-shader...)" 1.0 1.0 5.0 0.25 // Joint parameter with Linearize Pass pass, values must match
#define prescaley 1.0

#pragma stage fragment
layout(location = 0) in vec2 vTexCoord;
layout(location = 0) out vec4 FragColor;
layout(set = 1, binding = 0) uniform texture2D Source_texture;
layout(set = 1, binding = 1) uniform sampler Source;
layout(set = 1, binding = 2) uniform vec2 TextSize;

#define COMPAT_TEXTURE(c,d) texture(sampler2D(Source_texture,c),d)

float invsqrsigma = 1.0/(2.0*SIGMA_VB*SIGMA_VB);

float gaussian(float x)
{
return exp(-x*x*invsqrsigma);
}

void main()
{
vec2 invTextSize = 1 / TextSize;
vec4 OriginalSize = vec4(TextSize,invTextSize.x,invTextSize.y);
vec4 SourceSize = OriginalSize * vec4(prescalex, prescaley, (1.0/prescalex), (1.0/prescaley));
vec4 SourceSize1 = vec4(SourceSize.x, OriginalSize.y, SourceSize.z, OriginalSize.w);

float f = fract(SourceSize1.y * vTexCoord.y);
f = 0.5 - f;
vec2 tex = floor(SourceSize1.xy * vTexCoord)*SourceSize1.zw + 0.5*SourceSize1.zw;
vec4 color = vec4(0.0);
vec2 dy = vec2(0.0, SourceSize1.w);

float w;
float wsum = 0.0;
vec4 pixel;
float n = -SIZEVB;

do
{
pixel = COMPAT_TEXTURE(Source, tex + n*dy);
w = gaussian(n+f);
pixel.a*=pixel.a*pixel.a;
color = color + w * pixel;
wsum = wsum + w;
n = n + 1.0;

} while (n <= SIZEVB);

color = color / wsum;

float lenadj = pow(length(color.rgb) / sqrt(3), 0.75) * sqrt(3);

color = color * (lenadj/length(color.rgb));

FragColor = vec4(color.rgb, 1.0);
//FragColor = vec4(color.rgb, pow(color.a, 0.175));
}
Loading

0 comments on commit e841ab6

Please sign in to comment.