Sign in to follow this  
Spa8nky

Which of the following would be considered the better method?

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this