Jump to content
  • Advertisement
Sign in to follow this  
g0nzo

Simple HLSL question

This topic is 4415 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

Hi, I've got a pixel shader that does Gaussian blur. Now it looks like this:
float4 gaussOffsets[5]; // passed to the shader

float4 PS_5x5GaussianHorizontalPass( VSOutput input ) : COLOR
{    
  float gauss = 0.0f;  
  for( int i = 0; i < 5; i++ )
    gauss += tex2D( gaussTextureSampler, input.TexCoords + float2( gaussOffsets.r, 0.0f )).r * gaussOffsets.g;
  return float4(gauss, 0.0f, 0.0f, 0.0f);
}

technique Gaussian5x5Horizontal
{
  pass P0
  {
    VertexShader = null;
    PixelShader  = compile ps_2_0 PS_5x5GaussianHorizontalPass();
  }
}

Now I need a separate pixel shader and separate technique for every kernel size (there will be 7 different sizes). How to do it, so I could have just one pixel shader, many techniques and just pass necessary parameters (like kernel size, offsets and weights) to the pixel shader? If anyone could post a code for a pixel shader and single technique with parameters passed, I'd be very grateful.

Share this post


Link to post
Share on other sites
Advertisement
In some of the SDK examples they use multiple techniques, one of which you select when making use of the shader. Each technique could use the same vertex shader but have a different function in the file for the pixel shader.

I suggest you open up the projects in the SDK and take a peek. I think the HLSL Workshop example has what you require.

Dave

Share this post


Link to post
Share on other sites
Thanks.
I get the idea of multiple techniques, but I've got some problems with implementing what I need.

Here's what I got now:

float4 offsets[27]; // 27 is the maximum kernel size

float4 PS_GaussianHorizontal( VSOutput input, int samples, float4 offsets[27] )
{
float gauss= 0.0f;
for( int i = 0; i < samples; i++ )
gauss += tex2D( gaussTextureSampler, input.TexCoords + float2(offsets.r, 0.0f)).r * offsets.b;

return float4(gauss , 0.0f, 0.0f, 0.0f);
}

technique Gaussian5x5HorizontalPass
{
Pass P0
{
VertexShader = null;
PixelShader = compile ps_3_0 PS_GaussianHorizontal(5, offsets);
}
}




And I get the following error:

error X3013: 'PS_GaussianHorizontal': function does not take 2 parameters

I don't need to pass output of the vertex shader, so the pixel shader does take 2 parameters. Probably I'm incorrectly passing offsets array, but I don't know how it should look like.

Share this post


Link to post
Share on other sites
Try making use of the uniform keyword, I don't think the compilation stage will take dynamic/variable parameters (although regular HLSL "functions" will). The uniform keyword is analagous to a constant parameter (like you get in other languages) and thus the compile statement can hardcode the combination.

I make extensive use of uniform parameters in order to generate multiple shaders from the same/common HLSL code. You'll find lots of effects in the SDK and other samples do the same [smile]

hth
Jack

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.

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!