Jump to content
  • Advertisement
Sign in to follow this  
Spa8nky

Which of the following would be considered the better method?

This topic is 3129 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 guys, I am playing around in HLSL and was wondering which of the following methods would you recommend out of the following, and why: [METHOD 1]
float4 PixelShaderFunction(PixelShaderInput input) : COLOR0
{	
    // Look up the original image color
    float4 colour = tex2D(TextureSampler0, input.texCoord);

    // Adjust it to keep only values brighter than the specified threshold and return them
    return saturate((colour - BloomThreshold) / (1 - BloomThreshold));
}

[METHOD 2]
struct PixelShaderOutput
{
	float4 Colour	: COLOR0;
};

PixelShaderOutput PixelShaderFunction(PixelShaderInput input)
{	
	PixelShaderOutput Output = (PixelShaderOutput)0;

    // Look up the original image color
    float4 colour = tex2D(TextureSampler0, input.texCoord);

    // Adjust it to keep only values brighter than the specified threshold and return them
    Output.Colour = saturate((colour - BloomThreshold) / (1 - BloomThreshold));
    
    return Output;
}

Personally I prefer the second method, as it seems a lot clearer to me what is going on. Are there any reasons why I should use one method over another? What would you suggest? Thank you.

Share this post


Link to post
Share on other sites
Advertisement
The only real reason for using a structure for your pixel shader output is if you need to render to multiple COLOR registers, or the DEPTH register.

Although personally I use them in all my shaders just so they are consistent with each other. I have some that use the extra registers and some which don't.

Share this post


Link to post
Share on other sites
As far as efficiency goes, not really. I'm quite certain (though you can't be 100% certain without measuring instruction counts) they compile to the same thing.

Organizationally, I prefer the former because my pixel shaders almost always output to one register. Just go with what's consistent.

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!