コード例 #1
0
ファイル: RenderSimulator.cs プロジェクト: MMDaemon/ShaderSim
        private Bitmap CalculateFragmentStep()
        {
            int[]        imageData = new int[_fragments.GetLength(0) * _fragments.GetLength(1)];
            Vector4ToInt vec4ToInt = new Vector4ToInt();

            for (int x = 0; x < _fragments.GetLength(0); x++)
            {
                for (int y = 0; y < _fragments.GetLength(1); y++)
                {
                    if (_fragments[x, y] != null)
                    {
                        for (int i = 0; i < _fragments[x, y].Values.First().Count; i++)
                        {
                            bool closest = true;
                            if (DepthEnabled)
                            {
                                for (int j = 0; j < _depths[x, y].Count; j++)
                                {
                                    if (i != j)
                                    {
                                        if (_depths[x, y][i] > _depths[x, y][j])
                                        {
                                            closest = false;
                                        }
                                    }
                                }
                            }
                            if (closest)
                            {
                                foreach (var key in _fragments[x, y].Keys)
                                {
                                    SetAttribute(_activeFragmentShader, key, _fragments[x, y][key][i]);
                                }
                                _activeFragmentShader.Main();
                                foreach (var outValue in _activeFragmentShader.GetOutValues())
                                {
                                    if (outValue.Key == FragmentShader.ColorName)
                                    {
                                        vec4ToInt.ColorValue     = 0;
                                        vec4ToInt.valueA         = (byte)Math.Min((int)(((Vector4)outValue.Value).A * 255), 255);
                                        vec4ToInt.valueR         = (byte)Math.Min((int)(((Vector4)outValue.Value).R * 255), 255);
                                        vec4ToInt.valueG         = (byte)Math.Min((int)(((Vector4)outValue.Value).G * 255), 255);
                                        vec4ToInt.valueB         = (byte)Math.Min((int)(((Vector4)outValue.Value).B * 255), 255);
                                        imageData[x + y * Width] = vec4ToInt.ColorValue;
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return(new Bitmap(Width, Height, Width, System.Drawing.Imaging.PixelFormat.Format32bppArgb, Marshal.UnsafeAddrOfPinnedArrayElement(imageData, 0)));
        }