Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Share your shaders! #22

Open
yavko opened this issue Aug 4, 2023 · 23 comments · May be fixed by #37
Open

Share your shaders! #22

yavko opened this issue Aug 4, 2023 · 23 comments · May be fixed by #37

Comments

@yavko
Copy link
Member

yavko commented Aug 4, 2023

Shaders are pretty powerful, you can force colorschemes on your entire display, make modern LCD look like a 80s CRT, and other stuff I'm not even thinking of. So let's add a section for them. Problem is I have 1 shader, and having just one is pointless, so if you have any shaders or know someone who does please share shaders in the replies!

@yavko yavko changed the title Add shaders Share your shaders! Aug 4, 2023
@end-4
Copy link

end-4 commented Aug 4, 2023

  • shader by punished_ape. i like to call this one "drugs"
  • from: r/unixporn discord
  • description: applies waving effect and purple/pink tint. overall crazy shit
the shader
precision highp float;
varying vec2 v_texcoord;
uniform sampler2D tex;
uniform float time;

void warpco(inout vec2 tc) {
    tc -= 0.5;
    tc *= length(tc) * 2.0;
    tc += 0.5;
}

float rand1d(float seed) {
   return sin(seed*1454.0); 
}

float rand2d(vec2 co)
{
  return fract(sin(dot(co.xy, vec2(12.9898,78.233))) * 43758.5453);
}

vec3 rgb(in vec2 tc, float freq, float amp, inout vec4 centre) {
    vec2 off = vec2(1.0/800.0, 0.0) * sin(tc.t * freq + time) * amp;
    vec2 off2 = vec2(1.0/800.0, 0.0) * sin(tc.t * freq - time * 1.5) * amp;
    centre = texture2D(tex, tc);
    return vec3(texture2D(tex, tc-off).r, centre.g, texture2D(tex, tc+off2).b);
}

void main() {
    // vec2 px = 1.0 / textureSize(tex, 0).st;
    vec2 tc = v_texcoord;
    warpco(tc);
    tc = mix(v_texcoord, tc, sin(time * 2.0)*0.07);
    tc.x += rand2d(floor(tc * 20.0 + floor(time * 2.5))) * 0.01;
    tc.x += rand1d(floor(tc.x * 40.0)) * 0.005 * rand1d(time * 0.001);
    tc.y += sin(tc.x + time) * 0.02;
    vec4 centre;
    vec3 bent = rgb(tc, 100.0, 5.0, centre);
    vec3 col = mix(centre.rgb, bent, sin(time));
    gl_FragColor = vec4(col, centre.a);
    // gl_FragColor = vec4(texture2D(tex, v_texcoord));
}

edit: pasted the code directly here since the discord link doesn't last forever

@JustSimplyKyle
Copy link

https://github.com/sigma-957/hyprland-shaders/blob/main/crt.frag
my modified version based on it, added scanlines and some color corrections
crt.txt

@loqusion
Copy link

loqusion commented Aug 5, 2023

There's a blue light filter and vibrance, both of which are included in https://github.com/loqusion/hyprshade.

@paolobettelini
Copy link

I personally think we should have a dedicated place for this, with screenshots and everything. A GitHub issue isn't gonna cut it is it? What do you think?

@NotAShelf
Copy link
Member

I personally think we should have a dedicated place for this, with screenshots and everything. A GitHub issue isn't gonna cut it is it? What do you think?

the issue is to collect them, not to store them. as per the purpose of this repository, they will be store in this awesome-hyprland repository with links.

@yavko
Copy link
Member Author

yavko commented Aug 7, 2023

Yeah, I'll create something for them ;)

@loqusion
Copy link

loqusion commented Aug 7, 2023

I think we should at least store copies of them, in case the original sources get deleted.

@yavko
Copy link
Member Author

yavko commented Aug 8, 2023

Ofc

@mekb-turtle
Copy link

mekb-turtle commented Aug 17, 2023

simple blur shader
#version 330 core

precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

uniform int blurRadius = 1;

void main() {
	if (blurRadius <= 0) {
		gl_FragColor = texture(tex, v_texcoord);
		return;
	}

	vec2 invTextureSize = 1.0f / textureSize(tex, 0);
	float invBlurRadius = 1.0f / float(blurRadius);

	float samples = 0.0f;
	vec4 colorSum = vec4(0.0f);
	
	for (int x = -blurRadius; x <= blurRadius; ++x) {
		for (int y = -blurRadius; y <= blurRadius; ++y) {
			vec2 offset = vec2(x, y) * invTextureSize;

			float strength = 1 - (length(offset) * invBlurRadius);
			samples += strength;

			vec2 coords = v_texcoord + offset;
			colorSum += texture(tex, coords) * strength;
		}
	}
	
	colorSum /= samples;
	gl_FragColor = colorSum;
}

@yavko
Copy link
Member Author

yavko commented Aug 17, 2023

simple blur shader
#version 330 core

precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

uniform int blurRadius = 1;

void main() {
	if (blurRadius <= 0) {
		gl_FragColor = texture(tex, v_texcoord);
		return;
	}

	vec2 invTextureSize = 1.0f / textureSize(tex, 0);
	float invBlurRadius = 1.0f / float(blurRadius);

	float samples = 0.0f;
	vec4 colorSum = vec4(0.0f);
	
	for (int x = -blurRadius; x <= blurRadius; ++x) {
		for (int y = -blurRadius; y <= blurRadius; ++y) {
			vec2 offset = vec2(x, y) * invTextureSize;

			float strength = 1 - (length(offset) * invBlurRadius);
			samples += strength;

			vec2 coords = v_texcoord + offset;
			colorSum += texture(tex, coords) * strength;
		}
	}
	
	colorSum /= samples;
	gl_FragColor = colorSum;
}

What does this blur exactly, the whole screen?

@mekb-turtle
Copy link

What does this blur exactly, the whole screen?

yeah, no need for it though, just thought it'd be cool to make

@mekb-turtle
Copy link

also bloom shader
#version 330 core

precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

uniform int bloomRadius = 10;
uniform float bloomIntensity = 0.7f;
uniform float bloomThreshold = 0.4f;

void main() {
	vec4 color = texture(tex, v_texcoord);

	vec4 bloomThreshold4 = vec4(bloomThreshold);
	bloomThreshold4.w = 0.0f;

	vec2 invTextureSize = 1.0f / textureSize(tex, 0);
	float invBloomRadius = bloomRadius == 0 ? 1.0f : 1.0f / float(bloomRadius);
	float invBloomThreshold = 1.0f / (1.0f - bloomThreshold);

	float samples = 0.0f;
	vec4 colorSum = vec4(0.0f);
	
	for (int x = -bloomRadius; x <= bloomRadius; ++x) {
		for (int y = -bloomRadius; y <= bloomRadius; ++y) {
			vec2 offset = vec2(x, y) * invTextureSize;

			vec2 coords = v_texcoord + offset;
			vec4 color = texture(tex, coords);
			color = max(color - bloomThreshold, vec4(0.0f));

			float strength = 1 - (length(offset) * invBloomRadius);
			samples += strength;

			strength *= max(max(color.x, color.y), color.z) * invBloomThreshold;

			strength *= bloomIntensity;
			colorSum += color * strength;
		}
	}

	colorSum /= samples;
	gl_FragColor = min(color + colorSum, 1.0f);
}

@LamprosPitsillos
Copy link

Can you also post screenshots along with the shader ?
Makes browsing this thread easier , thanks!

@mekb-turtle
Copy link

i don't know how to with nvidia

@LamprosPitsillos
Copy link

i don't know how to with nvidia

https://github.com/hyprland-community/awesome-hyprland#screenshotting

@mekb-turtle
Copy link

https://github.com/hyprland-community/awesome-hyprland#screenshotting

sorry, I should've added more detail, screenshotting works fine but the shaders aren't applied to the screenshot

@LamprosPitsillos
Copy link

Ohhh didn't know sorry.
I imagine you would have to screenshot and theeen apply shader somehow, that's probably why noone posted screenshots

@ed-henrique
Copy link

monochromatic shader
precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

void main() {
   vec4 pixColor = texture2D(tex, v_texcoord);

   float lum = dot(pixColor.rgb, vec3(0.299, 0.587, 0.114));       // BT.601
   // float lum = dot(pixColor.rgb, vec3(0.2126, 0.7152, 0.0722)); // BT.709
   // float lum = dot(pixColor.rgb, vec3(0.2627, 0.6780, 0.0593)); // BT.2100
   // Check https://en.wikipedia.org/wiki/Grayscale for more information about which one to choose

   vec4 outCol = vec4(vec3(lum), pixColor.a);
   gl_FragColor = outCol;
}

@yavko
Copy link
Member Author

yavko commented Sep 13, 2023

Sick

yavko added a commit that referenced this issue Dec 11, 2023
Shaders from #22
@yavko yavko linked a pull request Dec 11, 2023 that will close this issue
3 tasks
@Euro20179
Copy link

Don't know if you're still accepting shaders since there is a pull request, but someone said I should put this here:
https://github.com/Euro20179/.files/blob/master/.config/hypr/shaders/crt.frag

It's another crt shader, but it's different from the one posted earlier

It's a modified version of this

And since someone wanted screenshots, here's a screenshot
screenshot

@yavko
Copy link
Member Author

yavko commented Dec 21, 2023

t from the one posted earlier

It's a modi

sick ill add it

@PsyNyde
Copy link

PsyNyde commented Dec 22, 2023

t from the one posted earlier
It's a modi

sick ill add it

I asked him to post it in here cause it doesn't use uniform lowp float time;
Shaders without time doesn't require damage_tracking to be disabled.

I think you should add some sort of note which shaders might need damage_tracking to be turned off when you add it.

@yavko
Copy link
Member Author

yavko commented Dec 22, 2023

t from the one posted earlier
It's a modi

sick ill add it

I asked him to post it in here cause it doesn't use uniform lowp float time;
Shaders without time doesn't require damage_tracking to be disabled.

I think you should add some sort of note which shaders might need damage_tracking to be turned off when you add it.

Oh is that so?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.