I need help with my fragment shader

i’m trying to convert the rgb to YCbCr for better color manipulation, but i can’t seem to figure it out.

const float Kr = 0.299;
const float Kg = 0.587;
const float Kb = 0.114;

void main()
{
	lowp vec4 tex = texture2D(texture_sampler, var_texcoord0.xy);
	vec4 tempfrag = tex * var_color;

	vec3 newcol=RGBtoYCBCR( vec3(tempfrag.x,tempfrag.y,tempfrag.z) );
}

vec3 RGBtoYCBCR(vec3 rgbcolor)
{
	float y=0.0;
	float Cb=0.0;
	float Cr=0.0;
	float r=rgbcolor.x;
	float g=rgbcolor.y;
	float b=rgbcolor.z;

	y=r*Kr+g*Kg+b*Kb;
	Cb=-0.5*(Kr/(1.0-Kb))*r -0.5*(Kg/(1.0-Kb))*g + 0.5*b  ;
	Cr=0.5*r -0.5*(Kg/(1.0-Kr))*g -0.5*(Kb/(1.0-Kr))*b; ;
return vec3(y,Cb,Cr);
}

it just spits some errors out, and i don’t really get why. i don’t see anywhere in my code that i’m converting a const float to a vec3.

Compatability issue: _generated_1951c3df.fpc2333632367242982588.glsl:          "precision mediump int; precision highp float;" 
_generated_1951c3df.fpc2333632367242982588.glsl:25: error: 'RGBtoYCBCR' : no matching overloaded function found
_generated_1951c3df.fpc2333632367242982588.glsl:25: error: '=' :  cannot convert from ' const float' to ' temp highp 3-component vector of float'

wait, can fragment constants even be used (changed) within the GUI?

Yes, it should be possible. You can send constants to your shader in the render.draw() call. Also note that you can use multiple materials in a GUI node nowadays.

You can send constants to your shader in the render.draw() call.

ok. i notice that the function renders all things with the material tag, is there a way to render one node at a time, since i’ll need them to have different parameters?
if not i can go with the lazy approach and just make a separate material for each (i know there will only be a small amount of nodes i need to do this on).

Why don’t you use fragment paramenters instead of constants? that way you can change them on a sprite basis in a script. (If I understand correctly what you are trying to do…)

that way you can change them on a sprite basis in a script

because i’m not using sprites, i’m using gui nodes

1 Like