help with ink shader[solved]

Hi, I have managed to make what I call “inkmap” custom shader, where the models I want to receive the ink effect appears in 2 colors, white for no ink and black for the ink effect. I use for this the model first texture, which contains the inkmap texture.

The problem is which using my inkmap with panda3d standard ink shader only the edges of the black areas are receive the ink effect, when all the black area should receive the ink effect. I´m having difficulties with the logic and thinking to make the ink shader fill not only edges, but entire black areas of the model. I also do not want to lose the edge detection which the standard panda ink shader does, I just want it to recognize texture ink overrides correctly.

Thanks for any help! The standard panda3d ink shader is below:

//Cg
//
//Cg profile arbvp1 arbfp1

void vshader(
	float4 vtx_position : POSITION,
	float4 vtx_texcoord0 : TEXCOORD0,
	out float4 l_position : POSITION,
	out float4 l_texcoord0 : TEXCOORD0,
	uniform float4x4 mat_modelproj
) {
  l_position=mul(mat_modelproj, vtx_position);
  l_texcoord0 = vtx_texcoord0;
}

void fshader(
	float4 l_texcoord0 : TEXCOORD0,
	uniform sampler2D tex_0 : TEXUNIT0,
	uniform float4 k_cutoff : C6,
	uniform float4 k_separation : C7,
	out float4 o_color : COLOR
) {
	float4 texcoord0 = l_texcoord0 + k_separation.xyzw;
	float4 color0=tex2D(tex_0, float2(texcoord0.x, texcoord0.y));
	float4 texcoord1 = l_texcoord0 - k_separation.xyzw;
	float4 color1=tex2D(tex_0, float2(texcoord1.x, texcoord1.y));
	float4 texcoord2 = l_texcoord0 + k_separation.wzyx;
	float4 color2=tex2D(tex_0, float2(texcoord2.x, texcoord2.y));
	float4 texcoord3 = l_texcoord0 - k_separation.wzyx;
	float4 color3=tex2D(tex_0, float2(texcoord3.x, texcoord3.y));
	float4 mx = max(color0,max(color1,max(color2,color3)));
	float4 mn = min(color0,min(color1,min(color2,color3)));
	float4 trigger = saturate( ((mx-mn)*3) - k_cutoff.x);
	float thresh = dot(float3(trigger.x, trigger.y, trigger.z),float3(1,1,1));
	float4 output_color = float4 (0, 0, 0, thresh);
	o_color = output_color;
}

Well, no help received, but here is what I managed to understand myself about the standard ink shader:

}

void fshader(
//receive the previous variable as input
   float4 l_texcoord0 : TEXCOORD0,

//
   uniform sampler2D tex_0 : TEXUNIT0,

//receive the 2 custom variables from panda3d side, created by the user
   uniform float4 k_cutoff : C6,
   uniform float4 k_separation : C7,

//
   out float4 o_color : COLOR
) {

//Here, for each pixel/fragment, the code below check the pixel color of the area before and after(+ and -) that pixel. This is done twice. 
   float4 texcoord0 = l_texcoord0 + k_separation.xyzw;
   float4 color0=tex2D(tex_0, float2(texcoord0.x, texcoord0.y));
   float4 texcoord1 = l_texcoord0 - k_separation.xyzw;
   float4 color1=tex2D(tex_0, float2(texcoord1.x, texcoord1.y));
   float4 texcoord2 = l_texcoord0 + k_separation.wzyx;
   float4 color2=tex2D(tex_0, float2(texcoord2.x, texcoord2.y));
   float4 texcoord3 = l_texcoord0 - k_separation.wzyx;
   float4 color3=tex2D(tex_0, float2(texcoord3.x, texcoord3.y));

//here we get the color with the highest and lowest value of all the 4 color samples above
   float4 mx = max(color0,max(color1,max(color2,color3)));
   float4 mn = min(color0,min(color1,min(color2,color3)));

//Here trigger is obtained by subtracting max-min color values, multiplied by 3(so the edge can be visible) and the result subtracted from the k_cutoff variable. The result of all is saturated(turned) in a value from 0 to 1.
   float4 trigger = saturate( ((mx-mn)*3) - k_cutoff.x);

//coudnt understand why to multiply trigger with 1 if it is already in range 0/1.
   float thresh = dot(float3(trigger.x, trigger.y, trigger.z),float3(1,1,1));

//thresh is then used as the alpha value of the output color, if alpha is 1 the black of the texture card(panda side) will be hidden, otherwise it will be shown, giving the effect of ink.
   float4 output_color = float4 (0, 0, 0, thresh);

//
   o_color = output_color;
}

This:

float thresh = dot(float3(trigger.x, trigger.y, trigger.z),float3(1,1,1));

Is just a trick to more efficiently do this:

float thresh = trigger.x + trigger.y + trigger.z;

I assume that is because shader compilers will translate it into a single dot3 instruction instead of multiple add instructions.

I see, thanks for explaining this! I managed to do most of the ink shader I wanted, here is the code, I just need to perfect it now.

	float4 texcoord0 = l_texcoord0;
//gets the current pixel/fragment color
	float4 color0=tex2D(tex_0, float2(texcoord0.x, texcoord0.y));
//alpha value ahead will be the override texture color	
	o_color = float4 (0, 0, 0, color0.x);

Your override texture need to be the first, white will be full black(white in cg rgb is 1,1,1 and 1 in alpha is opaque), and black no ink effect(black is cg rgb 0,0,0 and 0 in alpha is transparent), colors between these will have varying transparency.