Jump to content

  • Log In with Google      Sign In   
  • Create Account

Why multiply vector if you normalize it afterwards?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 noatom   Members   -  Reputation: 782

Like
0Likes
Like

Posted 16 January 2014 - 05:44 PM

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.

 

 



Sponsor:

#2 ferrous   Members   -  Reputation: 1997

Like
0Likes
Like

Posted 16 January 2014 - 06:04 PM

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.



#3 Doublefris   Members   -  Reputation: 315

Like
0Likes
Like

Posted 17 January 2014 - 04:36 AM

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



#4 sQuid   Members   -  Reputation: 149

Like
0Likes
Like

Posted 17 January 2014 - 12:55 PM

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






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS