private void DrawShadowSurface(Vector3 lightDirection, ITransformation lightCamera, ITexture2D positions, ITexture2D normals) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _shadowShader.Activate(); _depthSurface.Texture.WrapFunction = TextureWrapFunction.ClampToEdge; _shadowShader.ActivateTexture("lightDepth", 0, _depthSurface.Texture); _shadowShader.ActivateTexture("positions", 1, positions); _shadowShader.ActivateTexture("normals", 2, normals); _shadowShader.Uniform("lightDirection", lightDirection); _shadowShader.Uniform("lightCamera", lightCamera); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _shadowShader.DeactivateTexture(2, normals); _shadowShader.DeactivateTexture(1, positions); _shadowShader.DeactivateTexture(0, _depthSurface.Texture); _shadowShader.Deactivate(); _outputSurface.Deactivate(); }
public void Draw(IRenderState renderState, ITexture2D depth, float mipmapLevel = 0) { _geometries[_entity.Type].SetAttribute(_environmentMapProgram.GetResourceLocation(ShaderResourceType.Attribute, "transform"), new[] { _entity.Transform }, true); GL.ClearColor(Color.FromArgb(0, 0, 0, 0)); _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _environmentMapProgram.Activate(); _environmentMapProgram.ActivateTexture("cubeMap", 0, _cubeFbo.Texture); _environmentMapProgram.ActivateTexture("depth", 1, depth); _environmentMapProgram.Uniform("camera", _camera); Matrix4x4.Invert(_camera.Matrix, out var invert); _environmentMapProgram.Uniform("camPos", invert.Translation / invert.M44); _environmentMapProgram.Uniform("mipmapLevel", mipmapLevel); _geometries[_entity.Type].Draw(); _environmentMapProgram.DeactivateTexture(0, _cubeFbo.Texture); _environmentMapProgram.DeactivateTexture(1, depth); _environmentMapProgram.Deactivate(); _outputSurface.Deactivate(); GL.ClearColor(Color.FromArgb(0, 0, 0, 1)); }
public void Draw(IRenderState renderState, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, Dictionary <Enums.EntityType, ITexture2D> textures, Dictionary <Enums.EntityType, ITexture2D> normalMaps, List <Enums.EntityType> disableBackFaceCulling) { _outputSurface.Activate(); renderState.Set(new DepthTest(true)); GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 }); GL.DrawBuffers(4, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3 }); _deferredProgram.Activate(); _deferredProgram.Uniform("camera", camera); Matrix4x4.Invert(camera.Matrix, out var invert); _deferredProgram.Uniform("camPos", invert.Translation / invert.M44); foreach (var type in _geometries.Keys) { if (instanceCounts[type] == 0) { continue; } if (normalMaps.ContainsKey(type)) { _deferredProgram.ActivateTexture("normalMap", 1, normalMaps[type]); } else { _deferredProgram.ActivateTexture("normalMap", 1, _defaultMap); _deferredProgram.Uniform("normalMapping", 0f); _deferredProgram.Uniform("paralaxMapping", 0f); } if (textures.ContainsKey(type)) { _deferredProgram.ActivateTexture("tex", 0, textures[type]); _deferredProgram.Uniform("textured", 1f); } else { _deferredProgram.Uniform("materialColor", System.Drawing.Color.LightGray); _deferredProgram.Uniform("textured", 0f); } renderState.Set(disableBackFaceCulling.Contains(type) ? new BackFaceCulling(false) : new BackFaceCulling(true)); _geometries[type].Draw(instanceCounts[type]); if (textures.ContainsKey(type)) { _deferredProgram.DeactivateTexture(0, textures[type]); } } renderState.Set(new DepthTest(false)); renderState.Set(new BackFaceCulling(true)); _outputSurface.Deactivate(); }
public void Draw(ITransformation camera, ITexture2D materialColor, ITexture2D normals, ITexture2D position, ITexture2D shadowSurface, ITexture2D intensity, List <LightSource> lightSources) { if (lightSources.Count > _lightArraySizeInShader) { throw new ArgumentException("A maximum of " + _lightArraySizeInShader + " light sources is possible. See shader 'deferredLighting.glsl' for details."); } _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); _shader.Activate(); Matrix4x4.Invert(camera.Matrix, out var invert); _shader.Uniform("camPos", invert.Translation / invert.M44); _shader.Uniform("hemColorTop", new Vector3(0.9f, 0.9f, 1.0f)); _shader.Uniform("hemColorBottom", new Vector3(41.0f / 255.0f, 49.0f / 255.0f, 51.0f / 255.0f)); _shader.ActivateTexture("materialColor", 0, materialColor); _shader.ActivateTexture("normals", 1, normals); _shader.ActivateTexture("position", 2, position); _shader.ActivateTexture("shadowSurface", 3, shadowSurface); _shader.ActivateTexture("intensity", 4, intensity); var bufferObject = LightSourcesToBufferObject(lightSources); var loc = _shader.GetResourceLocation(ShaderResourceType.RWBuffer, "Lights"); bufferObject.ActivateBind(loc); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _shader.DeactivateTexture(4, intensity); _shader.DeactivateTexture(3, shadowSurface); _shader.DeactivateTexture(2, position); _shader.DeactivateTexture(1, normals); _shader.DeactivateTexture(0, materialColor); _shader.Deactivate(); _outputSurface.Deactivate(); }
public void Draw(ITexture2D texOne, ITexture2D texTwo, float factor = 1) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _addProgram.Activate(); _addProgram.ActivateTexture("image1", 0, texOne); _addProgram.ActivateTexture("image2", 1, texTwo); _addProgram.Uniform("factor", factor); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _addProgram.DeactivateTexture(1, texTwo); _addProgram.DeactivateTexture(0, texOne); _addProgram.Deactivate(); _outputSurface.Deactivate(); }
public void Draw(ITexture2D depth1, ITexture2D depth2, ITexture2D one1, ITexture2D one2, ITexture2D two1, ITexture2D two2, ITexture2D three1, ITexture2D three2, ITexture2D four1, ITexture2D four2, float offset = 0) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _addWithDepthTestProgram.Activate(); _addWithDepthTestProgram.ActivateTexture("depth1", 0, depth1); _addWithDepthTestProgram.ActivateTexture("depth2", 1, depth2); _addWithDepthTestProgram.Uniform("offset", offset); _addWithDepthTestProgram.ActivateTexture("bufferOne1", 2, one1); _addWithDepthTestProgram.ActivateTexture("bufferOne2", 3, one2); _addWithDepthTestProgram.ActivateTexture("bufferTwo1", 4, two1); _addWithDepthTestProgram.ActivateTexture("bufferTwo2", 5, two2); _addWithDepthTestProgram.ActivateTexture("bufferThree1", 6, three1); _addWithDepthTestProgram.ActivateTexture("bufferThree2", 7, three2); _addWithDepthTestProgram.ActivateTexture("bufferFour1", 8, four1); _addWithDepthTestProgram.ActivateTexture("bufferFour2", 9, four2); GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 }); GL.DrawBuffers(_drawBuffers.Length, _drawBuffers); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _addWithDepthTestProgram.DeactivateTexture(9, four2); _addWithDepthTestProgram.DeactivateTexture(8, four1); _addWithDepthTestProgram.DeactivateTexture(7, three2); _addWithDepthTestProgram.DeactivateTexture(6, three1); _addWithDepthTestProgram.DeactivateTexture(5, two2); _addWithDepthTestProgram.DeactivateTexture(4, two1); _addWithDepthTestProgram.DeactivateTexture(3, one2); _addWithDepthTestProgram.DeactivateTexture(2, one1); _addWithDepthTestProgram.DeactivateTexture(1, depth2); _addWithDepthTestProgram.DeactivateTexture(0, depth1); _addWithDepthTestProgram.Deactivate(); _outputSurface.Deactivate(); }
public void Draw(ITransformation camera, ITexture2D image, ITexture2D depth) { _outputSurface.Activate(); GL.ClearColor(Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _sphereCutProgram.Activate(); _sphereCutProgram.ActivateTexture("image", 1, image); _sphereCutProgram.ActivateTexture("depth", 0, depth); _sphereCutProgram.Uniform("camera", camera); _sphereGeometry.Draw(); _sphereCutProgram.DeactivateTexture(1, image); _sphereCutProgram.DeactivateTexture(0, depth); _sphereCutProgram.Deactivate(); _outputSurface.Deactivate(); }
public void Draw(ITexture2D dephtTexture, ITexture2D image) { _ssao.Draw(dephtTexture); _blur.Draw(_ssao.Output); _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); _shader.Activate(); _shader.ActivateTexture("saturation", 0, _blur.Output); _shader.ActivateTexture("image", 1, image); GL.DrawArrays(PrimitiveType.Quads, 0, 4); _shader.DeactivateTexture(1, image); _shader.DeactivateTexture(0, _blur.Output); _shader.Deactivate(); _outputSurface.Deactivate(); }
public void Draw(IRenderState renderState, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, Dictionary <Enums.EntityType, ITexture2D> textures, Dictionary <Enums.EntityType, ITexture2D> normalMaps, Dictionary <Enums.EntityType, ITexture2D> heightMaps, Dictionary <Enums.EntityType, Vector4> intensityMap, List <Enums.EntityType> disableBackFaceCulling, float time) { _deferredSurface.Activate(); renderState.Set(new DepthTest(true)); GL.ClearColor(System.Drawing.Color.FromArgb(0, 0, 0, 0)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 2, new float[] { 1000 }); GL.ClearBuffer(ClearBuffer.Color, 4, new float[] { 0, 0, 0, 0 }); GL.DrawBuffers(5, new[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2, DrawBuffersEnum.ColorAttachment3, DrawBuffersEnum.ColorAttachment4 }); _deferredProgram.Activate(); _deferredProgram.Uniform("camera", camera); Matrix4x4.Invert(camera.Matrix, out var invert); _deferredProgram.Uniform("camPos", invert.Translation / invert.M44); //TODO: Can be accelerated with sorting the normal map and not normal map useage beforhand foreach (var type in _geometries.Keys) { if (instanceCounts[type] == 0 || type == Enums.EntityType.NvidiaParticle || type == Enums.EntityType.RadeonParticle) { continue; } if (normalMaps.ContainsKey(type)) { _deferredProgram.ActivateTexture("normalMap", 1, normalMaps[type]); if (heightMaps.ContainsKey(type)) { _deferredProgram.ActivateTexture("heightMap", 2, heightMaps[type]); _deferredProgram.Uniform("normalMapping", 0f); _deferredProgram.Uniform("paralaxMapping", 1f); } else { _deferredProgram.ActivateTexture("heightMap", 2, _defaultMap); _deferredProgram.Uniform("normalMapping", 1f); _deferredProgram.Uniform("paralaxMapping", 0f); } } else { //_deferredProgram.ActivateTexture("normalMap", 1, _defaultMap); //_deferredProgram.ActivateTexture("heightMap", 2, _defaultMap); _deferredProgram.Uniform("normalMapping", 0f); _deferredProgram.Uniform("paralaxMapping", 0f); } if (textures.ContainsKey(type)) { _deferredProgram.ActivateTexture("tex", 0, textures[type]); _deferredProgram.Uniform("textured", 1f); } else { switch (type) { case Enums.EntityType.Voronoi: _deferredProgram.Uniform("materialColor", System.Drawing.Color.FromArgb(255, 41, 49, 51)); break; case Enums.EntityType.Crystal1: _deferredProgram.Uniform("materialColor", System.Drawing.Color.Pink); break; case Enums.EntityType.Crystal2: _deferredProgram.Uniform("materialColor", System.Drawing.Color.Cyan); break; default: _deferredProgram.Uniform("materialColor", System.Drawing.Color.LightGray); break; } _deferredProgram.Uniform("textured", 0f); } renderState.Set(disableBackFaceCulling.Contains(type) ? new BackFaceCulling(false) : new BackFaceCulling(true)); _deferredProgram.Uniform("intensity", intensityMap[type]); _geometries[type].Draw(instanceCounts[type]); if (textures.ContainsKey(type)) { _deferredProgram.DeactivateTexture(0, textures[type]); } if (normalMaps.ContainsKey(type)) { if (heightMaps.ContainsKey(type)) { _deferredProgram.DeactivateTexture(2, heightMaps[type]); } _deferredProgram.DeactivateTexture(1, normalMaps[type]); } //else //{ // _deferredProgram.DeactivateTexture(2, _defaultMap); // _deferredProgram.DeactivateTexture(1, _defaultMap); //} } renderState.Set(new DepthTest(false)); renderState.Set(new BackFaceCulling(true)); _deferredSurface.Deactivate(); _projectilesGenerationNvidia.Draw(renderState, camera, instanceCounts[Enums.EntityType.NvidiaParticle], intensityMap[Enums.EntityType.NvidiaParticle], time); _addProjectilesNvidia.Draw(_deferredSurface.Textures[2], _projectilesGenerationNvidia.Depth, _deferredSurface.Textures[0], _projectilesGenerationNvidia.Color, _deferredSurface.Textures[1], _projectilesGenerationNvidia.Normal, _deferredSurface.Textures[3], _projectilesGenerationNvidia.Position, _deferredSurface.Textures[4], _projectilesGenerationNvidia.IntensityMap); _projectilesGenerationRadeon.Draw(renderState, camera, instanceCounts[Enums.EntityType.RadeonParticle], intensityMap[Enums.EntityType.RadeonParticle], time); _addProjectilesRadeon.Draw(_addProjectilesNvidia.Depth, _projectilesGenerationRadeon.Depth, _addProjectilesNvidia.Color, _projectilesGenerationRadeon.Color, _addProjectilesNvidia.Normal, _projectilesGenerationRadeon.Normal, _addProjectilesNvidia.Position, _projectilesGenerationRadeon.Position, _addProjectilesNvidia.IntensityMap, _projectilesGenerationRadeon.IntensityMap); //_tesselation.Draw(renderState, camera, time); //_addTesselation.Draw(_addProjectilesRadeon.Depth, _tesselation.Depth, _addProjectilesRadeon.Color, _tesselation.Color, _addProjectilesRadeon.Normal, _tesselation.Normal, _addProjectilesRadeon.Position, _tesselation.Position, _addProjectilesRadeon.IntensityMap, _tesselation.IntensityMap); }