# HLSL float4 addition returning all 0.0f vector, unexpected result

Edit: Added images at the bottom to show the current issue.

I have the following few lines in my hlsl pixel shader where color and specular are both float4.

color = color * textureColor;

// Add specular component and clamp
color = saturate(color + specular);


Running VS2013 graphics debugger and debugging into the pixel shader I see specular coming through as (0.0f, 0.0f, 0.0f, 0.0f) which I expect for the pixel I'm checking since it's not within the specular portion of the viewDirection, but the float4 addition is making the final color as zero after the addition.

Am I completely missing something here? I would assume the following math:

   color (0.65f, 0.0f, 0.0f, 1.0f)
+ specular (0.0f, 0.0f, 0.0f, 0.0f)

result = (0.65f, 0.0f, 0.0f, 1.0f)


Any thoughts would be greatly appreciated. I have a feeling, I'm missing something really simple here.

EDIT:

 // If I remove the specular and return color after multi by tex Sample,
// I get the following expected result
color = color * textureColor;


// As soon as I add the specular component back in
color = saturate(color + specular);


• Please don't cross-post between SE sites. You should be able to delete your SO question since it has no answers; if not, please flag it for a moderator to move or delete. – user1430 Mar 10 '14 at 18:20
• Thank you for the tip. I've deleted it off SO as I feel it is more appropriate here. Slowly learning proper SE etiquette. – Mebourne Mar 10 '14 at 22:25
• How are you calculating diffuse and specular? You may need to clamp them individually before adding them: saturate(color + specular) -> saturate(color) + saturate(specular). – GuyRT Mar 13 '14 at 10:44
• Clearly, your specular is not a 0 vector, but contains negative numbers. The specular is zero on the backside of the sphere ( from the lights' view ) as seen on the last two images. – János Turánszki Mar 14 '14 at 0:45
• @JánosTuránszki I agree since the far right is showing the unlit red, but VS2013 Visual Graphics Debugger is still showing the specular vector come through as all 0.0f. – Mebourne Mar 14 '14 at 3:08