Color to alpha / no-alpha problem

Posted By: Rei_Ayanami

Color to alpha / no-alpha problem - 02/10/12 14:49

Heyo,

I got a little problem. I am writing shaders for Image Factory and one of them is a "color-to-alpha" shader [like the option in Gimp], but I cannot get the alpha transparency working.

Code:
float4 vecSkill1;
texture TargetMap;
sampler smpSource = sampler_state { texture = <TargetMap>; };

float4 ColorToAlpha_PS( float2 Tex : TEXCOORD0 ) : COLOR0
{
	float4 AlphaColor;
	float4 Color;

	AlphaColor = tex2D( smpSource, Tex.xy);

	AlphaColor.r -= vecSkill1.x;
	AlphaColor.g -= vecSkill1.y;
	AlphaColor.b -= vecSkill1.z;
	AlphaColor.a = abs(AlphaColor.r)+abs(AlphaColor.g)+abs(AlphaColor.b);
	AlphaColor.a /= 3;

	Color = tex2D( smpSource, Tex.xy);
	Color.a = AlphaColor.a;
	
	return Color;
}

technique tech_00
{
	pass pass_00
	{
		VertexShader = null;
		PixelShader = compile ps_2_0 ColorToAlpha_PS();
	}
}

technique fallback { pass one { } }



I also tried [for testing] to set the Color.a to the Color.r value, which resulted in semi-transparent red-parts and fully visible rest oO

May I misunderstood the shader thing?

[FYI: The shader is applied via bmap_process and the image is created via bmap_createblack, 32bits. ]

I am also having problems with alpha in other shaders, but this is the most important laugh [I will learn from it^^]


Thanks in advance,
Marian
Posted By: rojart

Re: Color to alpha / no-alpha problem - 02/10/12 14:58

Try to add below technique  AlphaBlendEnable = true;

Code:
technique tech_00
{
	pass pass_00
	{
                AlphaBlendEnable = true; 
		VertexShader = null;
		PixelShader = compile ps_2_0 ColorToAlpha_PS();
	}
}

technique fallback { pass one { } }



Posted By: Rei_Ayanami

Re: Color to alpha / no-alpha problem - 02/10/12 16:05

I, well - we [Sid and I] - are idiots.

Sorry, it was our fault, the target map contained the image, and due the fact that "AlphaBlendEnable" is turned on by default [it seems like that at least] we had to turn it off D:

Thanks for the hint!

Posted By: rojart

Re: Color to alpha / no-alpha problem - 02/11/12 00:58

I'm glad I could help. wink

Wow, a node-based shader editor, I've been waiting long time for this, is planed to make it like mentall mill or just for standard shaders?

btw, the result alpha seems to be scaled up, but there is nothing, like scale factor?

Mentall mill:


Posted By: Rei_Ayanami

Re: Color to alpha / no-alpha problem - 02/11/12 11:29

It is not really a shader editor [it was meant to be one, but then we realized that we are no shader programmers] so it became a 2D image-modifier/creator. Everyone can include their own (post-processing) shaders and functions (we have a written our own small language - noisescript).

What we are also trying to achieve is the creation of procedural textures.
© 2024 lite-C Forums