private void SumValues(ITexture2D sourceTexture, IShaderProgram program, IRenderSurface fbo) { int SATSampler = GL.GetUniformLocation(fullScreenQuad.ProgramID, "sourceSampler"); fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); program.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); program.Uniform("blockLengthX", blockSizeX); program.Uniform("blockLengthY", blockSizeX); program.Uniform("amountBlockX", amountBlocksX); program.Uniform("amountBlockY", amountBlocksX); //satFilter.GetFilterTexture().Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); //satFilter.GetFilterTexture().Deactivate(); program.Deactivate(); fbo.Deactivate(); }
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(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)); }
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(); }
//Filter FBO2 and Write result in FBO1[0] private void ProcessFilterPass(ITexture2D sourceTexture, IRenderSurface fbo) { int halfKernelX = kernelSizeX / 2; int halfKernelY = kernelSizeY / 2; fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shaderSATFilter.Activate(); int SATSampler = GL.GetUniformLocation(shaderSATFilter.ProgramID, "sourceSampler"); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); //sourceTexture.Activate(); shaderSATFilter.Uniform("width", sourceTexture.Width); shaderSATFilter.Uniform("height", sourceTexture.Height); shaderSATFilter.Uniform("halfKernelX", halfKernelX); shaderSATFilter.Uniform("halfKernelY", halfKernelY); GL.DrawArrays(PrimitiveType.Quads, 0, 4); //sourceTexture.Deactivate(); shaderSATFilter.Deactivate(); fbo.Deactivate(); }
private void DrawShadowSurface(IRenderState renderState, Vector3 lightDirection, ITransformation lightCamera, ITransformation camera, Dictionary <Enums.EntityType, int> instanceCounts, List <Enums.EntityType> disableBackFaceCulling) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _shadowShader.Activate(); _depthSurface.Texture.WrapFunction = TextureWrapFunction.ClampToEdge; _depthSurface.Texture.Activate(); _shadowShader.Uniform("lightDirection", lightDirection); _shadowShader.Uniform("lightCamera", lightCamera); _shadowShader.Uniform("camera", camera); GL.Uniform1(_shadowShader.GetResourceLocation(ShaderResourceType.Uniform, "lightDepth"), 0); foreach (var type in _geometriesDepth.Keys) { if (disableBackFaceCulling.Contains(type)) { renderState.Set(new BackFaceCulling(false)); } _geometriesShadow[type].Draw(instanceCounts[type]); renderState.Set(new BackFaceCulling(true)); } _depthSurface.Texture.Deactivate(); _shadowShader.Deactivate(); _outputSurface.Deactivate(); }
public void StartShadowMapPass() { shadowMapFBO.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderState.Set(new DepthTest(true)); renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE)); }
public void StartLightViewPass() { //Create ShadowMap lightViewFBO.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderState.Set(new DepthTest(true)); renderState.Set(new FaceCullingModeState(FaceCullingMode.FRONT_SIDE)); }
public void PointLightPass(Matrix4x4 cameraMatrix, Vector3 cameraPosition, Vector3 cameraDirection) { pointLightFBO.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderState.Set(new DepthTest(false)); renderState.Set(new FaceCullingModeState(FaceCullingMode.FRONT_SIDE)); renderState.Set(BlendStates.Additive); pointLightShader.Activate(); int position = GL.GetUniformLocation(pointLightShader.ProgramID, "positionSampler"); int albedo = GL.GetUniformLocation(pointLightShader.ProgramID, "albedoSampler"); int normal = GL.GetUniformLocation(pointLightShader.ProgramID, "normalSampler"); GL.Uniform1(position, 1); GL.Uniform1(albedo, 2); GL.Uniform1(normal, 3); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[0].ID); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[1].ID); GL.ActiveTexture(TextureUnit.Texture3); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[2].ID); pointLightShader.Uniform("camera", cameraMatrix); pointLightShader.Uniform("cameraPosition", cameraPosition); pointLightShader.Uniform("camDir", cameraDirection); GL.ActiveTexture(TextureUnit.Texture0); pointLightFBO.Textures[0].Activate(); DrawBuffersEnum[] drawBuffers = new DrawBuffersEnum[1]; drawBuffers[0] = DrawBuffersEnum.ColorAttachment0; GL.DrawBuffers(1, drawBuffers); pointLightSphere.Draw(pointLightAmount); GL.ActiveTexture(TextureUnit.Texture0); pointLightFBO.Textures[0].Deactivate(); pointLightShader.Deactivate(); renderState.Set(BlendStates.Opaque); renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE)); renderState.Set(new DepthTest(false)); pointLightFBO.Deactivate(); }
protected void DrawPass(ITexture2D inputTexture, IRenderSurface surface, IShaderProgram shader) { surface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); shader.Activate(); inputTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); inputTexture.Deactivate(); shader.Deactivate(); surface.Deactivate(); }
public void Draw(ITexture2D inputTexture) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _postProcessShader.Activate(); inputTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); inputTexture.Deactivate(); _postProcessShader.Deactivate(); _outputSurface.Deactivate(); }
private new void DrawPass(ITexture2D inputTexture, IRenderSurface surface, IShaderProgram shader) { surface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit); shader.Activate(); shader.Uniform("Size", _blurKernelSize); inputTexture.Activate(); GL.DrawArrays(PrimitiveType.Quads, 0, 4); inputTexture.Deactivate(); shader.Deactivate(); surface.Deactivate(); }
public void CreateMaps(float time) { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); mapFBO.Activate(); waterMapShader.Activate(); waterMapShader.Uniform("time", time); waterMapShader.Uniform("numberOfWaves", numberOfWaves); int buffer = waterMapShader.GetResourceLocation(ShaderResourceType.RWBuffer, "WavesBuffer"); waveBuffer.ActivateBind(buffer); //Activate Textures of FBO int textAmount = mapFBO.Textures.Count; //Number of Texture Channels of FBO for (int i = 0; i < textAmount; i++) { GL.ActiveTexture(TextureUnit.Texture0 + i); mapFBO.Textures[i].Activate(); } DrawBuffersEnum[] buffers = new DrawBuffersEnum[textAmount]; for (int i = 0; i < textAmount; i++) { buffers[i] = DrawBuffersEnum.ColorAttachment0 + i; } GL.DrawBuffers(textAmount, buffers); GL.DrawArrays(PrimitiveType.Quads, 0, 4); waveBuffer.Deactivate(); for (int i = textAmount - 1; i >= 0; i--) { GL.ActiveTexture(TextureUnit.Texture0 + i); mapFBO.Textures[i].Deactivate(); } waterMapShader.Deactivate(); mapFBO.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(ITransformation camera, float mipmapLevel = 0) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _skyboxProgram.Activate(); _cubeFbo.Texture.Activate(); _skyboxProgram.Uniform("mipmapLevel", mipmapLevel); _skyboxProgram.Uniform("camera", camera); _sphereGeometry.Draw(); _cubeFbo.Texture.Deactivate(); _skyboxProgram.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(IRenderState renderState, ITransformation camera, float time) { _outputSurface.Activate(); var oldBackFaceCullingState = renderState.Get <BackFaceCulling>(); var oldDepthTestState = renderState.Get <DepthTest>(); renderState.Set(new DepthTest(true)); renderState.Set(new BackFaceCulling(true)); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _tesselationProgram.Activate(); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Line); //Does not work with our FBOs. I don´t know why. Turn off for now or only test without FBO. GL.PatchParameter(PatchParameterInt.PatchVertices, 4); const int instanceSqrt = 3; _tesselationProgram.Uniform("camera", camera); _tesselationProgram.Uniform(nameof(instanceSqrt), instanceSqrt); _tesselationProgram.Uniform("iGlobalTime", time); _tesselationProgram.Uniform("size", 20); //Does not work _displacementMap.Activate(); 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.DrawArraysInstanced(PrimitiveType.Patches, 0, 4, instanceSqrt * instanceSqrt); GL.PolygonMode(MaterialFace.FrontAndBack, PolygonMode.Fill); _displacementMap.Deactivate(); _tesselationProgram.Deactivate(); renderState.Set(oldDepthTestState); renderState.Set(oldBackFaceCullingState); _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 Render() { if (shaderProgram is null) { return; } if (shaderProgramDepth is null) { return; } //first pass: create shadow map fboShadowMap.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shaderProgramDepth.Activate(); shaderProgramDepth.Uniform("ambient", new Vector3(0.1f, 0.1f, 0f)); shaderProgramDepth.Uniform("camera", light); geometry.Draw(); shaderProgramDepth.Deactivate(); fboShadowMap.Deactivate(); //GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); //TextureDebugger.Draw(fboShadowMap.Texture); //second pass: render with shadow map GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); shaderProgram.Activate(); fboShadowMap.Texture.Activate(); shaderProgram.Uniform("ambient", new Vector3(0.1f, 0.1f, 0f)); shaderProgram.Uniform("camera", Camera); shaderProgram.Uniform("lightCamera", light); geometry.Draw(); fboShadowMap.Texture.Deactivate(); shaderProgram.Deactivate(); }
private void DrawDepthSurface(IRenderState renderState, ITransformation lightCamera, Dictionary <Enums.EntityType, int> instanceCounts, List <Enums.EntityType> disableBackFaceCulling) { _depthSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.ClearBuffer(ClearBuffer.Color, 0, new float[] { 10000 }); _depthShader.Activate(); _depthShader.Uniform("camera", lightCamera); foreach (var type in _geometriesDepth.Keys) { if (disableBackFaceCulling.Contains(type)) { renderState.Set(new BackFaceCulling(false)); } _geometriesDepth[type].Draw(instanceCounts[type]); renderState.Set(new BackFaceCulling(true)); } _depthShader.Deactivate(); _depthSurface.Deactivate(); }
private void DrawFullQuad(ITexture2D sourceTexture, IRenderSurface fbo) { int SATSampler = GL.GetUniformLocation(fullScreenQuad.ProgramID, "inputTexture"); fbo.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); renderState.Set(new DepthTest(true)); renderState.Set(new FaceCullingModeState(FaceCullingMode.BACK_SIDE)); fullScreenQuad.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); GL.Uniform1(SATSampler, 0); GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, sourceTexture.ID); GL.DrawArrays(PrimitiveType.Quads, 0, 4); fullScreenQuad.Deactivate(); renderState.Set(new FaceCullingModeState(FaceCullingMode.NONE)); renderState.Set(new DepthTest(false)); fbo.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); }
private static void Update(IRenderSurface oldRenderSurface, IRenderSurface renderSurface) { oldRenderSurface?.Deactivate(); //TODO: maybe view port and 0 buffer, but should be done by deactivate renderSurface?.Activate(); }
public void Draw(IRenderState renderState, ITransformation camera, int trianglesCount, Vector4 intensity, float time) { _outputSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _projectileGenerationProgram.Activate(); Matrix4x4.Invert(camera.Matrix, out var invert); _projectileGenerationProgram.Uniform("camPos", invert.Translation / invert.M44); _projectileGenerationProgram.Uniform("camera", camera); _projectileGenerationProgram.Uniform("time", time); _projectileGenerationProgram.Uniform("normalMapping", 0f); _projectileGenerationProgram.Uniform("paralaxMapping", 0f); _projectileGenerationProgram.Uniform("intensity", intensity); switch (_triangleType) { case Enums.EntityType.NvidiaParticle: _projectileGenerationProgram.Uniform("materialColor", new Vector4(0, 100, 0, 5)); break; case Enums.EntityType.RadeonParticle: _projectileGenerationProgram.Uniform("materialColor", new Vector4(100, 0, 0, 5)); break; default: Console.WriteLine("No origin for triangle found"); _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.Blue); break; } _projectileGenerationProgram.Uniform("textured", 0f); 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); _trianglesGeometry.Draw(trianglesCount); _projectileGenerationProgram.Deactivate(); _outputSurface.Deactivate(); _wireSurface.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); _projectileGenerationProgram.Activate(); _projectileGenerationProgram.Uniform("camPos", invert.Translation / invert.M44); _projectileGenerationProgram.Uniform("camera", camera); _projectileGenerationProgram.Uniform("time", time); _projectileGenerationProgram.Uniform("normalMapping", 0f); _projectileGenerationProgram.Uniform("paralaxMapping", 0f); _projectileGenerationProgram.Uniform("intensity", intensity); switch (_triangleType) { case Enums.EntityType.NvidiaParticle: _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.DarkGreen); break; case Enums.EntityType.RadeonParticle: _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.DarkRed); break; default: Console.WriteLine("No origin for triangle found"); _projectileGenerationProgram.Uniform("materialColor", System.Drawing.Color.DarkBlue); break; } _projectileGenerationProgram.Uniform("textured", 0f); 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.PolygonMode(MaterialFace.Front, PolygonMode.Line); _trianglesGeometry.Draw(trianglesCount); GL.PolygonMode(MaterialFace.Front, PolygonMode.Fill); _projectileGenerationProgram.Deactivate(); _wireSurface.Deactivate(); _add.Draw(_outputSurface.Textures[2], _wireSurface.Textures[2], _outputSurface.Textures[0], _wireSurface.Textures[0], _outputSurface.Textures[0], _wireSurface.Textures[0], _outputSurface.Textures[0], _wireSurface.Textures[0], _outputSurface.Textures[0], _wireSurface.Textures[0], -0.01f); }
public void StartGeometryPass() { GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); mainFBO.Activate(); GL.Clear(ClearBufferMask.ColorBufferBit | ClearBufferMask.DepthBufferBit); }
public void FinalPass(Vector3 cameraPosition, Vector4 ambientColor, DirectionalLight dirLight, Vector3 cameraDirection, bool renderToTexture) { int textAmount = finalPassFBO.Textures.Count; //Number of Texture Channels of FBO if (renderToTexture) { finalPassFBO.Activate(); for (int i = 0; i < textAmount; i++) { GL.ActiveTexture(TextureUnit.Texture0 + i); finalPassFBO.Textures[i].Activate(); } DrawBuffersEnum[] buffers = new DrawBuffersEnum[textAmount]; for (int i = 0; i < textAmount; i++) { buffers[i] = DrawBuffersEnum.ColorAttachment0 + i; } GL.DrawBuffers(textAmount, buffers); } deferredPost.Activate(); //renderState.Set(BlendStates.Additive); //Activate Textures of FBO int position = GL.GetUniformLocation(deferredPost.ProgramID, "positionSampler"); int albedo = GL.GetUniformLocation(deferredPost.ProgramID, "albedoSampler"); int normal = GL.GetUniformLocation(deferredPost.ProgramID, "normalSampler"); int lights = GL.GetUniformLocation(deferredPost.ProgramID, "pointLightSampler"); int shadows = GL.GetUniformLocation(deferredPost.ProgramID, "shadowSampler"); int unlit = GL.GetUniformLocation(deferredPost.ProgramID, "unlitSampler"); GL.Uniform1(position, 1); GL.Uniform1(albedo, 2); GL.Uniform1(normal, 3); GL.Uniform1(lights, 4); GL.Uniform1(shadows, 5); GL.Uniform1(unlit, 6); GL.ActiveTexture(TextureUnit.Texture1); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[0].ID); GL.ActiveTexture(TextureUnit.Texture2); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[1].ID); GL.ActiveTexture(TextureUnit.Texture3); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[2].ID); GL.ActiveTexture(TextureUnit.Texture4); GL.BindTexture(TextureTarget.Texture2D, pointLightFBO.Textures[0].ID); GL.ActiveTexture(TextureUnit.Texture5); GL.BindTexture(TextureTarget.Texture2D, shadowMapFBO.Texture.ID); GL.ActiveTexture(TextureUnit.Texture6); GL.BindTexture(TextureTarget.Texture2D, mainFBO.Textures[4].ID); //Pass Parameters deferredPost.Uniform("ambientColor", ambientColor); deferredPost.Uniform("camPos", cameraPosition); deferredPost.Uniform("camDir", cameraDirection); deferredPost.Uniform("dirLightDir", dirLight.direction); deferredPost.Uniform("dirLightCol", dirLight.lightColor); deferredPost.Uniform("dirSpecCol", dirLight.specularColor); deferredPost.Uniform("dirIntensity", dirLight.intensity); deferredPost.Uniform("dirSpecIntensity", dirLight.specularIntensity); deferredPost.Uniform("specFactor", dirLight.specularFactor); //PostProcessQuad GL.DrawArrays(PrimitiveType.Quads, 0, 4); deferredPost.Deactivate(); renderState.Set(BlendStates.Opaque); if (renderToTexture) { for (int i = textAmount - 1; i >= 0; i--) { GL.ActiveTexture(TextureUnit.Texture0 + i); mainFBO.Textures[i].Deactivate(); } finalPassFBO.Deactivate(); //TextureDebugger.Draw(finalPassFBO.Texture); } }