Sign in to follow this  

Why multiply vector if you normalize it afterwards?

This topic is 1460 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

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.
        specularIntensity = shaderTextures[2].Sample(SampleType, input.tex);

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


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites
Sign in to follow this