When I change this:

float attenuation = 1.0f / d*d;To this:

float attenuation = 1.0f / ( d*d );

My model is no longer lit, and is instead the color of my ambient intensity. I find this extremely strange. The reason I want parentheses is so I can use a different attenuation function such as ( 1 + 0.045*d + 0.0075*d*d ).

It also messes up if I try this:

float denominator = d*d; float attenuation = 1.0f / denominator;

Here is my entire pixel shader. The reason for all of the "tmp_stuff" variables is to make everything "politically correct" since I have no choice but to input them as float4 due to constant buffer alignment properties. I would rather convert everything to temporary float3 rather than risk the chance of something not working right because of float4. Anyways, it shouldn't have anything to do with my current problem. I've doubled, tripled, and quad-checked my lighting equations with four different books, and I'm just baffled with this problem.

void ps( in v2p input, out float4 final_color : SV_TARGET ) { float3 ambient_intensity = float3( 0.1f, 0.1f, 0.1f ); float3 diffuse_color = float3( 0.8f, 0.8f, 0.8f); float3 specular_color = float3( 1.0f, 1.0f , 1.0f ); float3 tmp_light; tmp_light.x = light_vector.x; tmp_light.y = light_vector.y; tmp_light.z = light_vector.z; float3 norm_light = normalize( tmp_light ); float3 tmp_pos; tmp_pos.x = input.pos.x; tmp_pos.y = input.pos.y; tmp_pos.z = input.pos.z; float3 tmp_norm; tmp_norm.x = input.norm.x; tmp_norm.y = input.norm.y; tmp_norm.z = input.norm.z; float3 tmp_cam = float3( 0.0f, 0.0f, -20.0f ); // fixed view camera position // light intensity float d = distance( tmp_pos, tmp_light ); float attenuation = 1.0f/d*d; // HERE IS THE PROBLEM AREA float3 pointlight = attenuation*float3( light_color.x, light_color.y, light_color.z ); // diffuse lighting float diffuse = max( dot( tmp_norm, norm_light) , 0.0f ); float3 diffuse_final = diffuse_color*ambient_intensity + diffuse_color*pointlight*diffuse; // specular lighting float3 reflect_vect = 2*dot( tmp_norm, norm_light )*tmp_norm - norm_light; float ref_max = max( dot( reflect_vect, normalize(tmp_cam) ), 0.0f ); float spec_exponent = pow ( ref_max, 50.0f ); float3 spec_final; if( dot( tmp_norm, norm_light ) <= 0 ) { spec_final = float3( 0.0f, 0.0f, 0.0f ); } if( dot( tmp_norm, norm_light ) > 0 ) { spec_final = specular_color*pointlight*spec_exponent; } final_color = float4( diffuse_final + spec_final, 1.0f ); }

Without parentheses:

With parentheses:

**Edited by eowdaoc, 13 September 2012 - 03:23 PM.**