本文整理汇总了C#中Balder.Core.Math.Vector.Normalize方法的典型用法代码示例。如果您正苦于以下问题:C# Vector.Normalize方法的具体用法?C# Vector.Normalize怎么用?C# Vector.Normalize使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Balder.Core.Math.Vector
的用法示例。
在下文中一共展示了Vector.Normalize方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Calculate
public override Color Calculate(Vector point, Vector normal)
{
// Use dotproduct for diffuse lighting. Add point functionality as this now is a directional light.
// Ambient light
var ambient = ColorAmbient.ToVector() * Strength;
// Diffuse light
var lightDir = Direction;
lightDir.Normalize();
normal.Normalize();
var dfDot = lightDir.Dot(normal);
MathHelper.Saturate(ref dfDot);
var diffuse = ColorDiffuse.ToVector() * dfDot * Strength;
// Specular highlight
var Reflection = 2 * dfDot * normal - lightDir;
Reflection.Normalize();
var view = Camera.Position - point;
view.Normalize();
var spDot = Reflection.Dot(view);
MathHelper.Saturate(ref spDot);
var specular = ColorSpecular.ToVector() * spDot * Strength;
// Compute self shadowing
var shadow = 4.0f * lightDir.Dot(normal);
MathHelper.Saturate(ref shadow);
// Final result
var colorVector = ambient + shadow * (diffuse + specular);
//var colorVector = ambient + diffuse;
return colorVector.ToColorWithClamp();
}
示例2: Calculate
public override Color Calculate(Viewport viewport, Vector point, Vector normal)
{
var actualAmbient = Ambient;
var actualDiffuse = Diffuse;
var actualSpecular = Specular;
// Use dotproduct for diffuse lighting. Add point functionality as this now is a directional light.
// Ambient light
var ambient = actualAmbient * Strength;
// Diffuse light
var lightDir = Position-point;
lightDir.Normalize();
normal.Normalize();
var dfDot = lightDir.Dot(normal);
dfDot = MathHelper.Saturate(dfDot);
var diffuse = actualDiffuse * dfDot * Strength;
// Specular highlight
var reflection = 2f * dfDot * normal - lightDir;
reflection.Normalize();
var view = viewport.View.Position - point;
view.Normalize();
var spDot = reflection.Dot(view);
spDot = MathHelper.Saturate(spDot);
var specular = actualSpecular * spDot * Strength;
// Compute self shadowing
var shadow = 4.0f * lightDir.Dot(normal);
shadow = MathHelper.Saturate(shadow);
// Compute range for the light
var attenuation = ((lightDir / Range).Dot(lightDir / Range));
attenuation = MathHelper.Saturate(attenuation);
attenuation = 1f - attenuation;
// Final result
var colorVector = ambient + shadow * (diffuse + specular) * attenuation;
//var colorVector = ambient + diffuse;
return colorVector;
}