Exemplo n.º 1
0
 private static void SetPixelIfInside(DirectBitmap bitmap, int x, int y, FragColor color)
 {
     if (x > 0 && x < bitmap.Width && y > 0 && y < bitmap.Height)
     {
         bitmap.SetPixel(x, y, color);
     }
 }
Exemplo n.º 2
0
        public void SetPixel(int x, int y, FragColor color)
        {
            int index = x + (y * Width);
            int col   = color.Color.ToArgb();

            Bits[index] = col;
        }
Exemplo n.º 3
0
        private static FragColor CalculatePixelColor(Vector3 position, Vector3 normal, Vector2 texCoords, Vector3 cameraPos, Material material, IList <Light> lights, DirectBitmap texture)
        {
            var pixelColor = new FragColor();
            var kd         = texture?.GetPixel(texCoords) ?? material.DiffuseColor;

            foreach (var light in lights)
            {
                // diffuse
                var lightDir = (light.Position - position).Normalized;
                var diff     = Math.Max(Vector3.Dot(normal, lightDir), 0);
                var diffuse  = diff * kd * light.DiffuseLight;

                // specular
                var viewDir    = (cameraPos - position).Normalized;
                var reflectDir = Vector3.Reflect(-lightDir, normal);
                var spec       = (float)Math.Pow(Math.Max(Vector3.Dot(viewDir, reflectDir), 0.0f), material.Shininess);
                var specular   = spec * material.SpecularColor * light.SpecularLight;

                pixelColor += material.AmbientColor * AmbientLight + (diffuse + specular) * GetAttenuation(light, position);
            }
            return(pixelColor);
        }