Welcome, Guest.
Username: Password: Remember me

TOPIC: Color Shift Shader

Color Shift Shader 1 year 3 days ago #1

Here's a shader that shifts the color of the entire frame buffer by a given number of degrees on the color wheel. Great for making games of red vs blue complete unplayable. It functions by converting the RGB color to YIQ color space and then shifting in the IQ plane. By default the shader will cycle through every hue just like the color shift video effect you often see in youtube videos. You can set the speed faster or slower, or you can set it to zero and have a static color shift if you like.

The real meat of the code is actually from J. "fluffy" Shagam and made available under the Creative Commons Attribution-NonCommercial-ShareAlike license. As such, this shader is distributed with credit to him under that license. You can find more information about this license here. You can find more of fluffy's work here and you can find a detailed explanation of the code used in this shader specifically here.

This is the original image:


And this image has been color shifted:


/*
	This code is shared under the Creative Commons Attribution-NonCommercial-ShareAlike license.
	You can find more information about this license at https://creativecommons.org/licenses/by-nc-sa/2.5/
	This file contains code written by J. "fluffy" Shagam and made available under the same license.
	You can find more of fluffy's work at https://beesbuzz.biz
	Feel free to modify and share any code in this file, but make sure you honor fluffy's original license.
*/

#include "ReShade.fxh"

uniform float speed <
	ui_type = "drag";
	ui_min = 0;
	ui_max = 100;
	ui_label = "Speed";
	ui_tooltip = "Speed in which to cycle between colors. Set to zero for a static color shift.";
> = 10;

uniform float shift <
	ui_type = "drag";
	ui_min = 0;
	ui_max = 360;
	ui_label = "Shift";
	ui_tooltip = "Number of degrees to shift the hue of the input image.";
> = 60;

uniform int framecount < source = "framecount"; >;
static const float PI = 3.14159265f;

float3 PS_colorCycle(float4 pos : SV_Position, float2 texcoord : TexCoord) : SV_Target {
	float3 input = tex2D(ReShade::BackBuffer, texcoord).rgb;
	float3 output;
	
	float offset = shift + (framecount*speed/10);
	
	/* 	
		The following code is copyright J. "fluffy" Shagam and made available to the public 
		under the Creative Commons Attribution-NonCommercial-ShareAlike license.
		You can find more information about this license at https://creativecommons.org/licenses/by-nc-sa/2.5/
		You can find more of fluffy's work at https://beesbuzz.biz
		You can find this code specifically at https://beesbuzz.biz/code/hsv_color_transforms.php
	*/
	
	float U = cos(offset*PI/180);
	float W = sin(offset*PI/180);

	output.r = (.299+.701*U+.168*W)*input.r
	+ (.587-.587*U+.330*W)*input.g
	+ (.114-.114*U-.497*W)*input.b;
	output.g = (.299-.299*U-.328*W)*input.r
	+ (.587+.413*U+.035*W)*input.g
	+ (.114-.114*U+.292*W)*input.b;
	output.b = (.299-.3*U+1.25*W)*input.r
	+ (.587-.588*U-1.05*W)*input.g
	+ (.114+.886*U-.203*W)*input.b;
	
	return output;
}

technique colorCycle {
	pass colorCycle {
		VertexShader=PostProcessVS;
		PixelShader=PS_colorCycle;
	}
}
The administrator has disabled public write access.