当前位置: 首页>>代码示例>>C#>>正文


C# Vector.Normalize方法代码示例

本文整理汇总了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();
		}
开发者ID:baldercollaborator,项目名称:Balder,代码行数:34,代码来源:DirectionalLight.cs

示例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;
        }
开发者ID:petriw,项目名称:Balder,代码行数:42,代码来源:OmniLight.cs


注:本文中的Balder.Core.Math.Vector.Normalize方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。