loqusion / hyprshade

Hyprland shader configuration tool
MIT License
280 stars 7 forks source link

Reduce intensity? #13

Closed H1manshu-Soni closed 7 months ago

H1manshu-Soni commented 9 months ago

Is there a way to reduce intensity on the "night-light-filter"? If not I think its a must have!

id-ekaagr commented 9 months ago

Try this config:

// link: https://github.com/hyprwm/Hyprland/issues/1140#issuecomment-1614863627
precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

const float X = 2.0;
const float R = X * X;
const float G = R * R;
const float B = G * G;
const float VIB_VIBRANCE = 1.0 / (R + B + G);
const vec3 VIB_RGB_BALANCE = vec3(
  R,
  G,
  B
);

const vec3 VIB_coeffVibrance = VIB_RGB_BALANCE * -VIB_VIBRANCE;

void main() {
  vec4 pixColor = texture2D(tex, v_texcoord);
  vec3 color = vec3 (
    pixColor[0],
    pixColor[1],
    pixColor[2]
  );

  vec3 VIB_coefLuma = vec3(
    R / (R + B + G),
    G / (R + B + G),
    B / (R + B + G)
  ) * X;

  float luma = dot(VIB_coefLuma, color);

  float max_color = max(color[0], max(color[1], color[2]));
  float min_color = min(color[0], min(color[1], color[2]));

  float color_saturation = max_color - min_color;

  vec3 p_col = vec3(vec3(vec3(vec3(sign(VIB_coeffVibrance) * color_saturation) - 1.0) * VIB_coeffVibrance) + 1.0);

  pixColor[0] = mix(luma, color[0], p_col[0]);
  pixColor[1] = mix(luma, color[1], p_col[1]);
  pixColor[2] = mix(luma, color[2], p_col[2]);

  gl_FragColor = pixColor;
}
loqusion commented 9 months ago

Good idea, I think I'll add it as a config option in hyprshade.toml.

loqusion commented 9 months ago

So, what I'm thinking is there could be a configuration key (e.g. blue-light-filter.temperature) added to hyprshade.toml and running hyprshade install could generate a blue-light-filter.glsl in the user's shaders directory with the specified value, which would take priority over the system blue-light-filter.glsl.

What are your thoughts?

Sytxx commented 9 months ago

yea thats good, like you can make preset or something that you can modify (e.g using percent for the intensity).

H1manshu-Soni commented 9 months ago

Try this config:

// link: https://github.com/hyprwm/Hyprland/issues/1140#issuecomment-1614863627
precision mediump float;
varying vec2 v_texcoord;
uniform sampler2D tex;

const float X = 2.0;
const float R = X * X;
const float G = R * R;
const float B = G * G;
const float VIB_VIBRANCE = 1.0 / (R + B + G);
const vec3 VIB_RGB_BALANCE = vec3(
  R,
  G,
  B
);

const vec3 VIB_coeffVibrance = VIB_RGB_BALANCE * -VIB_VIBRANCE;

void main() {
  vec4 pixColor = texture2D(tex, v_texcoord);
  vec3 color = vec3 (
    pixColor[0],
    pixColor[1],
    pixColor[2]
  );

  vec3 VIB_coefLuma = vec3(
    R / (R + B + G),
    G / (R + B + G),
    B / (R + B + G)
  ) * X;

  float luma = dot(VIB_coefLuma, color);

  float max_color = max(color[0], max(color[1], color[2]));
  float min_color = min(color[0], min(color[1], color[2]));

  float color_saturation = max_color - min_color;

  vec3 p_col = vec3(vec3(vec3(vec3(sign(VIB_coeffVibrance) * color_saturation) - 1.0) * VIB_coeffVibrance) + 1.0);

  pixColor[0] = mix(luma, color[0], p_col[0]);
  pixColor[1] = mix(luma, color[1], p_col[1]);
  pixColor[2] = mix(luma, color[2], p_col[2]);

  gl_FragColor = pixColor;
}

gives an error saying " expected '=' "

this is what the entire toml file looks like:

[[shades]] name = "vibrance" default = true # shader to use during times when there is no other shader scheduled

[[shades]] name = "blue-light-filter" start_time = 19:00:00 end_time = 06:00:00 # optional if you have more than one shade with start_time

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

const float X = 2.0; const float R = X X; const float G = R R; const float B = G * G; const float VIB_VIBRANCE = 1.0 / (R + B + G); const vec3 VIB_RGB_BALANCE = vec3( R, G, B );

const vec3 VIB_coeffVibrance = VIB_RGB_BALANCE * -VIB_VIBRANCE;

void main() { vec4 pixColor = texture2D(tex, v_texcoord); vec3 color = vec3 ( pixColor[0], pixColor[1], pixColor[2] );

vec3 VIB_coefLuma = vec3( R / (R + B + G), G / (R + B + G), B / (R + B + G) ) * X;

float luma = dot(VIB_coefLuma, color);

float max_color = max(color[0], max(color[1], color[2])); float min_color = min(color[0], min(color[1], color[2]));

float color_saturation = max_color - min_color;

vec3 p_col = vec3(vec3(vec3(vec3(sign(VIB_coeffVibrance) color_saturation) - 1.0) VIB_coeffVibrance) + 1.0);

pixColor[0] = mix(luma, color[0], p_col[0]); pixColor[1] = mix(luma, color[1], p_col[1]); pixColor[2] = mix(luma, color[2], p_col[2]);

gl_FragColor = pixColor; }

I removed the "//...." line because it said invalid statement

id-ekaagr commented 9 months ago

save the code below in a file highlight.glsl then use Hyprland's screen_shader feature setting.

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

const float X = 1.0;

const float N = 1.0 + X;
const float R = N * N;
const float G = R * R;
const float B = G * G;
const float S = R + G + B;
const float VIB_VIBRANCE = 1.0 / S;
const vec3 VIB_RGB_BALANCE = vec3(
  R,
  G,
  B
);

const vec3 VIB_coeffVibrance = VIB_RGB_BALANCE * -VIB_VIBRANCE;

void main() {
  vec4 pixColor = texture2D(tex, v_texcoord);
  vec3 color = vec3(pixColor[0], pixColor[1], pixColor[2]);

  vec3 VIB_coefLuma = vec3(R / S, G / S, B / S) * R;

  float luma = dot(VIB_coefLuma, color);

  float max_color = max(color[0], max(color[1], color[2]));
  float min_color = min(color[0], min(color[1], color[2]));

  float color_saturation = max_color - min_color;

  vec3 p_col = vec3(vec3(vec3(vec3(sign(VIB_coeffVibrance) * color_saturation) - 1.0) * VIB_coeffVibrance) + 1.0);

  pixColor[0] = mix(luma, color[0], p_col[0]);
  pixColor[1] = mix(luma, color[1], p_col[1]);
  pixColor[2] = mix(luma, color[2], p_col[2]);

  gl_FragColor = pixColor;
}
devolskii commented 7 months ago

Is there a way to reduce intensity on the "night-light-filter"? If not I think its a must have!

I just rewrote line 7 of /usr/share/hyprshade/shaders/blue-light-filter.glsl as: const float temperature = 3000.0

Tweaking this temperature variable can help you achieve the filter intensity as required.

H1manshu-Soni commented 7 months ago

Is there a way to reduce intensity on the "night-light-filter"? If not I think its a must have!

I just rewrote line 7 of /usr/share/hyprshade/shaders/blue-light-filter.glsl as: const float temperature = 3000.0

Tweaking this temperature variable can help you achieve the filter intensity as required.

a neat solution :+1: