Jump to content
  • Advertisement
Sign in to follow this  
freeworld

[HLSL] Help with outline glow effect

This topic is 3711 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I trying to create a glow like outline, that is the color of the near-by pixels. I got it all working... sorta... the colors don't match up properly or are to bright, there for altering the colors. Heres a few picture to explain what I mean, the effect file will be below it. Heres a pic withe colors to be sampled, the background image isn't being sampled, just the green and red. The outline effect is still in place in the image. Photobucket Heres how it looks with the efect, notice the colors arn't exact, but seem to be brighter. Photobucket Here's the Effect file with the HLSL code.
float4x4 WorldViewProjection : WORLDVIEWPROJECTION;

struct VS_OUTPUT
{
    float4 Pos : POSITION; 
    float2 UV  : TEXCOORD0;
};

struct PS_OUTPUT
{
    float4 Color : COLOR0;
};

Texture Tex;
float2 TexScale;
sampler coloredtexture = sampler_state
{
    Texture = <Tex>;
    magfilter = LINEAR;
    minfilter = LINEAR;
    mipfilter = LINEAR;
    AddressU  = mirror;
    AddressV  = mirror;
};


VS_OUTPUT VShader(float4 Pos : POSITION,
                  float2 UV  : TEXCOORD0)
{
    VS_OUTPUT Out;
    Out.Pos = mul(Pos, WorldViewProjection);
    Out.UV  = UV;
    return Out;
}

PS_OUTPUT PShader(float2 UV  : TEXCOORD0)
{
    PS_OUTPUT Out;
    float2 tuv;
    float4 color_l;
    float4 color_r;
    float4 color_u;
    float4 color_d;
	float4 color_l2;
    float4 color_r2;
    float4 color_u2;
    float4 color_d2;
    float a = 0;
	float r = 0;
	float g = 0;
	float b = 0;

    Out.Color = tex2D(coloredtexture, UV); 

    tuv = UV;
    tuv.x -= TexScale.x;
    color_l = tex2D(coloredtexture, tuv);
    tuv = UV;
    tuv.x += TexScale.x;
    color_r = tex2D(coloredtexture, tuv);
    tuv = UV;
    tuv.y -= TexScale.y;
    color_u = tex2D(coloredtexture, tuv);
    tuv = UV;
    tuv.y += TexScale.y;
    color_d = tex2D(coloredtexture, tuv);

	tuv = UV;
    tuv.x -= (TexScale.x * 2);
    color_l2 = tex2D(coloredtexture, tuv);
    tuv = UV;
    tuv.x += (TexScale.x * 2);
    color_r2 = tex2D(coloredtexture, tuv);
    tuv = UV;
    tuv.y -= (TexScale.y * 2);
    color_u2 = tex2D(coloredtexture, tuv);
    tuv = UV;
    tuv.y += (TexScale.y * 2);
    color_d2 = tex2D(coloredtexture, tuv);

    if (Out.Color.a < 0.3)
    {
		// first outline of pixels
        if (color_l.a > 0)
		{
            a += color_l.a;
			r += color_l.r;
			g += color_l.g;
			b += color_l.b;
		}
        if (color_r.a > 0)
		{
            a += color_r.a;
			r += color_r.r;
			g += color_r.g;
			b += color_r.b;
		}  
		if (color_u.a > 0)
		{
            a += color_u.a;
			r += color_u.r;
			g += color_u.g;
			b += color_u.b;
		} 
		if (color_d.a > 0)
		{
            a += color_d.a;
			r += color_d.r;
			g += color_d.g;
			b += color_d.b;
		}

		// second outline of pixels
		if (color_l2.a > 0)
		{
            a += color_l2.a;
			r += color_l2.r;
			g += color_l2.g;
			b += color_l2.b;
		}
        if (color_r2.a > 0)
		{
            a += color_r2.a;
			r += color_r2.r;
			g += color_r2.g;
			b += color_r2.b;
		}  
		if (color_u2.a > 0)
		{
            a += color_u2.a;
			r += color_u2.r;
			g += color_u2.g;
			b += color_u2.b;
		} 
		if (color_d2.a > 0)
		{
            a += color_d2.a;
			r += color_d2.r;
			g += color_d2.g;
			b += color_d2.b;
		}
       

        if (a > 0)
            Out.Color = float4(r, g, b, a*2);
    }
    else
        Out.Color = float4(1.0f, 0.5f, 0.5f, 0.1);
       
    return Out;
}

technique RenderScreen
{
    pass P0
    {
        vertexshader = compile vs_2_0 VShader();
        pixelshader = compile ps_2_0 PShader();
    }
}




Share this post


Link to post
Share on other sites
Advertisement
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!