Jump to content
  • Advertisement
Sign in to follow this  
Underwood

Edge Detection Shader

This topic is 3583 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 am doing a post process edge detection shader and I have been reading a lot from the "Shaders" book by Sebastueb St-Laurent (the big black shaders book). I understand a good portion of it until some of the post process effects. They use RenderMonkey for all there examples and set the values viewport_inv_width/viewport_inv_height. Only I am not sure what these values should be and with my current code the shader is completely wrong. Does anyone see what the problem is with my code?
// World * View * Projection Matrix
float4x4 worldViewProjectionMatrix;	

// The texture to use.
texture tCurrentTexture;

float viewportWidth;
float viewportHeight;

const float4 samples[6] = {
    -1.0,    1.0,    0,    1.0,
    0.0,    1.0,    0,    2.0,
    1.0,    1.0,   0,    1.0,
    -1.0,    -1.0,   0,    -1.0,
    0.0,    -1.0,   0,    -2.0,
    1.0,    -1.0,   0,    -1.0
};
     
sampler2D sTexture = sampler_state
{
	Texture = <tCurrentTexture>;
	MagFilter = NONE;
	MinFilter = NONE;
	MipFilter = NONE;
};

struct VS_INPUT
{
	float3 position : POSITION;
	float2 texCoord : TEXCOORD0;
	float3 normal : NORMAL;
};

struct VS_OUTPUT
{
	float4 outPos : POSITION;
	float2 texCoord : TEXCOORD0;
};

VS_OUTPUT VS(VS_INPUT IN)
{
	VS_OUTPUT OUT;

	OUT.outPos = mul(float4(IN.position, 1.0f), worldViewProjectionMatrix);
	OUT.texCoord = IN.texCoord;

	return OUT;
}

float4 PS(VS_OUTPUT IN) : COLOR
{
    //return tex2D(sTexture, IN.texCoord);
    float4 col = float4(0.0f, 0.0f, 0.0f, 0.0f);
    
   for(int i=0;i<6;i++)
      col += samples.w*tex2D(sTexture, IN.texCoord+
       float2(samples.x*viewportWidth,
              samples.y*viewportHeight));
            
    return col;
}

technique BasicTexture
{
	pass
	{
		VertexShader = compile vs_2_0 VS();
		PixelShader = compile ps_2_0 PS();
	}
}

Share this post


Link to post
Share on other sites
Advertisement
I guess this is something like 1.0f / 1024.0f, 1.0f / 768.0f ... so the size of a texel?

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!