public View(bool debug = false) { GL.BlendFunc(BlendingFactor.SrcAlpha, BlendingFactor.OneMinusSrcAlpha); GL.Enable(EnableCap.Blend); _wrapper = debug ? (RenderWrapper) new RenderSimulator() : new RenderTranslator(); _vertex = new LightedVertex(); _fragment = new LightedFragment(); if (_wrapper is RenderTranslator translator) { string directory = Directory.GetCurrentDirectory(); translator.RegisterShader(_vertex, _fragment, directory + @"\..\..\Shaders\" + _vertex.GetType().Name + ".cs", directory + @"\..\..\Shaders\" + _fragment.GetType().Name + ".cs"); } }
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 < _fragmentCount[x, y]; i++) { bool closest = true; if (DepthEnabled) { /*if (_depths[x, y][i] < 0) * { * closest = false; * continue; * }*/ for (int j = 0; j < _depths[x, y].Count; j++) { if (i != j /*&& _depths[x, y][j] >= 0*/) { if (_depths[x, y][i] > _depths[x, y][j]) { closest = false; break; } } } } if (closest) { foreach (var key in _fragments[x, y].Keys) { var type = _activeFragmentShader.GetType(); var prop = type.GetProperty(key); var value = _fragments[x, y][key][i]; prop.SetValue(_activeFragmentShader, value); } _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))); }