Skip to content

Commit f4d89b3

Browse files
committed
Enhance character rendering in Hero component for responsive design
- Implemented dynamic scaling for character grid and pixel size based on screen width. - Adjusted character size to improve display on mobile devices. - Updated texture sampling to accommodate different resolutions for better visual fidelity.
1 parent 40a0a76 commit f4d89b3

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/components/hero/index.tsx

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ uniform vec2 uResolution;
6060
uniform sampler2D uTexture;
6161
out vec4 fragColor;
6262
float character(int n, vec2 p) {
63-
p = floor(p * vec2(-4.0, 4.0) + 2.5);
63+
// character grid scale
64+
float scale = uResolution.x < 768.0 ? 6.0 : 4.0;
65+
p = floor(p * vec2(-scale, scale) + 2.5);
6466
if(clamp(p.x, 0.0, 4.0) == p.x && clamp(p.y, 0.0, 4.0) == p.y) {
6567
int a = int(round(p.x) + 5.0 * round(p.y));
6668
if(((n >> a) & 1) == 1) return 0.8;
@@ -69,7 +71,9 @@ float character(int n, vec2 p) {
6971
}
7072
void main() {
7173
vec2 pix = gl_FragCoord.xy;
72-
vec3 col = texture(uTexture, floor(pix / 16.0) * 16.0 / uResolution.xy).rgb;
74+
// pixel size
75+
float pixelSize = uResolution.x < 768.0 ? 12.0 : 16.0;
76+
vec3 col = texture(uTexture, floor(pix / pixelSize) * pixelSize / uResolution.xy).rgb;
7377
float gray = 0.3 * col.r + 0.59 * col.g + 0.11 * col.b;
7478
int n = 2048;
7579
if(gray > 0.2) n = 65600;
@@ -79,7 +83,9 @@ void main() {
7983
if(gray > 0.6) n = 15252014;
8084
if(gray > 0.7) n = 13195790;
8185
if(gray > 0.8) n = 11512810;
82-
vec2 p = mod(pix / 8.0, 2.0) - vec2(1.0);
86+
// char size
87+
float charSize = uResolution.x < 768.0 ? 6.0 : 8.0;
88+
vec2 p = mod(pix / charSize, 2.0) - vec2(1.0);
8389
col = vec3(character(n, p));
8490
if (gray < 0.2) {
8591
col *= 0.4;

0 commit comments

Comments
 (0)