# Why multiply vector if you normalize it afterwards?

This topic is 2100 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

So I was looking through the rastertek website,and I found this snippet:

 If the light intensity is greater than zero we will do specular light calculations.

if(lightIntensity > 0.0f)
{

Here is where we sample the specular map for the intensity of specular light at this pixel.

// Sample the pixel from the specular map texture.

In the reflection calculation we use the bump map normal instead of the regular input normal.

// Calculate the reflection vector based on the light intensity, normal vector, and light direction.
reflection = normalize(2 * lightIntensity * bumpNormal - lightDir);

// Determine the amount of specular light based on the reflection vector, viewing direction, and specular power.
specular = pow(saturate(dot(reflection, input.viewDirection)), specularPower);

Now that we have the amount of specular light at this pixel we then multiply it by the specular intensity from the specular map to get a final value.

// Use the specular map to determine the intensity of specular light at this pixel.
specular = specular * specularIntensity;

// Add the specular component last to the output color.
color = saturate(color + specular);
}

return color;
}


    // Calculate the amount of light on this pixel based on the bump map normal value.
lightIntensity = saturate(dot(bumpNormal, lightDir));

reflection = normalize(2 * lightIntensity * bumpNormal - lightDir);

All my interest is in that line. First,why multiply the vector in the first place,if you'll normalize it later.Second,why multiply by 2?(just for a better effect?) And finally,why multiply by lightIntensity too? I know that the dot product gives a result that is connected with the length of the vectors but still...i can't connect it all out.

##### Share on other sites

Dot product is |a||b|cos(Theta), so assuming that lightdir is also normalized, they are looking to calculate cosTheta, and not some scalar of cosTheta.

##### Share on other sites

lightdir and bumpnormal are probably not usually collinear in this case, so the direction wil not usually be the same.

##### Share on other sites

Try reading it again, you'll see that they're not multiplying the entire argument vector by 2. :-)

• ### Game Developer Survey

We are looking for qualified game developers to participate in a 10-minute online survey. Qualified participants will be offered a \$15 incentive for your time and insights. Click here to start!

• 13
• 18
• 15
• 11
• 9
×

## Important Information

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!