public void RenderWaterReflection(WaterPlane water, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane, bool bApplyLensFlareScale = false) { if (m_postConstructor) { return; } Matrix4 modelMatrix = Matrix4.Identity; if (bApplyLensFlareScale) { modelMatrix *= Matrix4.CreateScale(LENS_FLARE_SIZE_TO_SUN_SIZE, -LENS_FLARE_SIZE_TO_SUN_SIZE, LENS_FLARE_SIZE_TO_SUN_SIZE); } float translationPositionY = (2 * water.GetTranslation().Y) - m_lightSource.Position.Y; modelMatrix *= Matrix4.CreateTranslation(m_lightSource.Position.X, translationPositionY, m_lightSource.Position.Z); GL.Enable(EnableCap.ClipDistance0); m_shader.startProgram(); m_texture1.BindTexture(TextureUnit.Texture0); m_texture2.BindTexture(TextureUnit.Texture1); m_shader.setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix, m_lightSource, 0, 1); m_shader.SetClipPlane(ref clipPlane); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); m_buffer.RenderVAO(PrimitiveType.Triangles); GL.Disable(EnableCap.Blend); m_shader.stopProgram(); GL.Disable(EnableCap.ClipDistance0); }
public void RenderWaterReflection(WaterPlane water, BaseCamera camera, Vector3 sunDirection, Matrix4 projectionMatrix, Vector4 clipPlane) { if (m_bPostConstructor) { return; } GL.Enable(EnableCap.ClipDistance0); Matrix4 mirrorMatrix; mirrorMatrix = GetMirrorMatrix(water); m_shader.startProgram(); m_skyboxDayTexture.BindTexture(TextureUnit.Texture0); m_skyboxNightTexture.BindTexture(TextureUnit.Texture1); m_shader.SetTransformationMatrices(ref projectionMatrix, camera.GetViewMatrix(), ref mirrorMatrix); m_shader.SetDayCubeTexture(0); m_shader.SetNightCubeTexture(1); m_shader.SetDayCycleValue(sunDirection.Normalized().Y); m_shader.SetMist(m_mist); m_shader.SetClipPlane(ref clipPlane); m_buffer.RenderVAO(PrimitiveType.Triangles); m_shader.stopProgram(); GL.Disable(EnableCap.ClipDistance0); }
public void RenderWater(BaseCamera camera, ref Matrix4 projectionMatrix, float nearClipPlane, float farClipPlane , DirectionalLight sun = null, List <PointLight> lights = null) { PostConstructor(); /*Water distortion cycle*/ m_shader.startProgram(); m_fbo.ReflectionTexture.BindTexture(TextureUnit.Texture0); m_fbo.RefractionTexture.BindTexture(TextureUnit.Texture1); m_waterDistortionMap.BindTexture(TextureUnit.Texture2); m_waterNormalMap.BindTexture(TextureUnit.Texture3); m_fbo.DepthTexture.BindTexture(TextureUnit.Texture4); m_shader.setTransformationMatrices(ref m_modelMatrix, camera.GetViewMatrix(), ref projectionMatrix); m_shader.setReflectionSampler(0); m_shader.setRefractionSampler(1); m_shader.setDuDvSampler(2); m_shader.setNormalMapSampler(3); m_shader.setDepthSampler(4); m_shader.setCameraPosition(camera.GetEyeVector()); m_shader.setDistortionProperties(m_moveFactor, m_waveStrength); m_shader.setDirectionalLight(sun); m_shader.setPointLight(lights); m_shader.setClippingPlanes(ref nearClipPlane, ref farClipPlane); m_shader.setMist(m_mist); m_shader.setTransparancyDepth(TransparencyDepth); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); m_buffer.RenderVAO(PrimitiveType.Triangles); GL.Disable(EnableCap.Blend); m_shader.stopProgram(); }
public static ITexture CopyTexture(ITexture src) { ITexture dst = PoolProxy.GetResource <ObtainRenderTargetPool, RenderTargetAllocationPolicy, TextureParameters, ITexture>(src.GetTextureParameters()); var renderTarget = GL.GenFramebuffer(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, renderTarget); GL.FramebufferTexture2D(FramebufferTarget.Framebuffer, FramebufferAttachment.ColorAttachment0, src.GetTextureParameters().TexTarget, dst.GetTextureDescriptor(), 0); GL.DrawBuffer(DrawBufferMode.ColorAttachment0); //GL.Disable(EnableCap.DepthTest); GL.Viewport(0, 0, src.GetTextureRezolution().X, src.GetTextureRezolution().Y); // start copy texture to render target copyShader.startProgram(); src.BindTexture(TextureUnit.Texture0); copyShader.SetUniformValues(0); var quadBuffer = ScreenQuad.GetScreenQuadBuffer(); quadBuffer.RenderVAO(PrimitiveType.Triangles); copyShader.stopProgram(); GL.Enable(EnableCap.DepthTest); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.DeleteFramebuffer(renderTarget); return(dst); }
public virtual void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix) { Matrix4 worldMatrix = GetWorldMatrix(); texture.BindTexture(TextureUnit.Texture0); shader.startProgram(); shader.SetTransformatrionMatrices(worldMatrix, viewMatrix, projectionMatrix); shader.SetDiffuseTexture(0); shader.SetOpacity(0.2f); GL.Enable(EnableCap.CullFace); GL.CullFace(CullFaceMode.Back); GL.Enable(EnableCap.Blend); GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha); VAOManager.renderBuffers(model.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles); GL.Disable(EnableCap.Blend); GL.Disable(EnableCap.CullFace); shader.stopProgram(); foreach (var item in ChildrenComponents) { SceneComponent comp = item as SceneComponent; if (comp != null) { comp.Render(viewMatrix, projectionMatrix); } } }
public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix) { if (bPostConstructor) { shader = PoolProxy.GetResource <ObtainShaderPool, ShaderAllocationPolicy <SkyboxShader>, string, SkyboxShader>(String.Format("{0}{1},{0}{2}", ProjectFolders.ShadersPath, "skyboxVS.glsl", "skyboxFS.glsl")); model = new RawModel(attribs); cubemap = ProxyTextureLoader.LoadCubemap(new string[] { ProjectFolders.SkyboxTexturesPath + "/Day/" + "right.bmp", ProjectFolders.SkyboxTexturesPath + "/Day/" + "left.bmp", ProjectFolders.SkyboxTexturesPath + "/Day/" + "top.bmp", ProjectFolders.SkyboxTexturesPath + "/Day/" + "bottom.bmp", ProjectFolders.SkyboxTexturesPath + "/Day/" + "back.bmp", ProjectFolders.SkyboxTexturesPath + "/Day/" + "front.bmp" }); bPostConstructor = false; } shader.startProgram(); cubemap.BindTexture(OpenTK.Graphics.OpenGL.TextureUnit.Texture0); shader.SetTransformationMatrices(Matrix4.Identity, viewMatrix, projectionMatrix); shader.SetCubemap(0); VAOManager.renderBuffers(model.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles); shader.stopProgram(); }
public override ITexture GetPostProcessResult(ITexture frameColorTexture, ITexture frameDepthTexture, Point actualScreenRezolution, ITexture previousPostProcessResult = null) { postConstructor(); if (this.blurWidthChanged) { this.blurWeights = normalizedWeights(BlurWidth); this.blurWidthChanged = false; } /*Render bright parts of the image to vertical blur render target*/ renderTarget.renderToFBO(1, renderTarget.verticalBlurTexture.GetTextureRezolution()); //GL.Disable(EnableCap.DepthTest); bloomShader.startProgram(); frameColorTexture.BindTexture(TextureUnit.Texture0); bloomShader.setExtractingBrightPixelsUniforms(0, BloomThreshold); quadBuffer.RenderVAO(PrimitiveType.Triangles); bloomShader.stopProgram(); /*Gauss blur*/ for (Int32 i = 0; i < BlurPassCount; i++) { /*Horizontal blur of image*/ renderTarget.renderToFBO(2, renderTarget.horizontalBlurTexture.GetTextureRezolution()); bloomShader.startProgram(); renderTarget.verticalBlurTexture.BindTexture(TextureUnit.Texture0); bloomShader.setHorizontalBlurUniforms(0, blurWeights, getPixOffset(BlurWidth), renderTarget.verticalBlurTexture.GetTextureRezolution()); quadBuffer.RenderVAO(PrimitiveType.Triangles); bloomShader.stopProgram(); /*Vertical blur of bright parts of image*/ renderTarget.renderToFBO(1, renderTarget.verticalBlurTexture.GetTextureRezolution()); bloomShader.startProgram(); renderTarget.horizontalBlurTexture.BindTexture(TextureUnit.Texture0); bloomShader.setVerticalBlurUniforms(0, blurWeights, getPixOffset(BlurWidth), renderTarget.horizontalBlurTexture.GetTextureRezolution()); quadBuffer.RenderVAO(PrimitiveType.Triangles); bloomShader.stopProgram(); } // Blend bloom post process result with previous post process result, if such exists renderTarget.renderToFBO(3, renderTarget.bloomResultTexture.GetTextureRezolution()); bloomShader.startProgram(); if (previousPostProcessResult != null) { previousPostProcessResult.BindTexture(TextureUnit.Texture1); bloomShader.SetPreviousPostProcessResultSampler(1); } renderTarget.verticalBlurTexture.BindTexture(TextureUnit.Texture0); bloomShader.setEndBloomUniforms(0); quadBuffer.RenderVAO(PrimitiveType.Triangles); bloomShader.stopProgram(); renderTarget.unbindFramebuffer(); GL.Enable(EnableCap.DepthTest); return(renderTarget.bloomResultTexture); }
public void render(BaseCamera camera, ref Matrix4 projectionMatrix) { postConstructor(); Matrix4 modelMatrix = Matrix4.Identity; GetShader().startProgram(); m_texture.BindTexture(TextureUnit.Texture0); m_envMap.BindTexture(TextureUnit.Texture1); GetShader().setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref projectionMatrix, camera.GetEyeVector(), 0, 1); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); GetShader().stopProgram(); }
public virtual void RenderEntity(PrimitiveType mode, DirectionalLight directionalLight, List <PointLight> lights, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { postConstructor(); Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*If clip plane is set - enable clipping plane*/ if (clipPlane.X == 0 && clipPlane.Y == 0 && clipPlane.Z == 0 && clipPlane.W == 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } GetShader().startProgram(); // pass uniform variables to shader if (directionalLight != null && directionalLight.GetHasShadow()) { DirectionalLightWithShadow lightWithShadow = directionalLight as DirectionalLightWithShadow; // Get shadow handler ITexture shadowMap = lightWithShadow.GetShadowMapTexture(); shadowMap.BindTexture(TextureUnit.Texture1); GetShader().SetDirectionalLightShadowMatrix(lightWithShadow.GetShadowMatrix(ref modelMatrix, ref ProjectionMatrix)); } m_texture.BindTexture(TextureUnit.Texture0); bool bEnableNormalMap = m_normalMap != null; if (bEnableNormalMap) { m_normalMap.BindTexture(TextureUnit.Texture2); } GetShader().SetDiffuseMap(0); GetShader().SetNormalMap(2, bEnableNormalMap); GetShader().SetMaterial(m_material); GetShader().SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); GetShader().SetPointLights(GetRelevantPointLights(lights)); GetShader().SetDirectionalLight(directionalLight); GetShader().SetClippingPlane(ref clipPlane); GetShader().SetMist(m_mist); GetShader().SetDirectionalLightShadowMap(1); m_skin.Buffer.RenderVAO(mode); GetShader().stopProgram(); }
public void Render(BaseCamera camera, Matrix4 projectionMatrix) { postConstructor(); foreach (PointLight lamp in _lamps) { Matrix4 modelMatrix = Matrix4.CreateTranslation(lamp.Position.Xyz); _shader.startProgram(); _texture.BindTexture(TextureUnit.Texture0); _shader.setUniformValues(modelMatrix, camera.GetViewMatrix(), projectionMatrix, 0); _buffer.RenderVAO(PrimitiveType.Points); _shader.stopProgram(); } }
public void RenderFullScreenInputTexture(ITexture renderTexture, Point screenRezolution) { PostConstructor(); GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.Viewport(0, 0, screenRezolution.X, screenRezolution.Y); _shader.startProgram(); renderTexture.BindTexture(TextureUnit.Texture0); _shader.SetUiTextureSampler(0); _shader.SetScreenSpaceMatrix(Matrix4.Identity); _shader.SetIsDepthTexture(false); _shader.SetIsSeparatedScreen(false); _buffer.RenderVAO(PrimitiveType.Triangles); _shader.stopProgram(); }
public void RenderWaterReflection(WaterPlane water, DirectionalLight Sun, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane) { if (m_bPostConstructor) { return; } float translationPositionY = (2 * water.GetTranslation().Y); Matrix4 mirrorMatrix, modelMatrix = Matrix4.Identity; mirrorMatrix = Matrix4.CreateScale(1, -1, 1); mirrorMatrix *= Matrix4.CreateTranslation(0, translationPositionY, 0); GL.Enable(EnableCap.ClipDistance0); liteReflectionShader.startProgram(); _textureBlack.BindTexture(TextureUnit.Texture0); _textureR.BindTexture(TextureUnit.Texture1); _textureG.BindTexture(TextureUnit.Texture2); _textureB.BindTexture(TextureUnit.Texture3); _blendMap.BindTexture(TextureUnit.Texture4); liteReflectionShader.SetTextureR(1); liteReflectionShader.SetTextureG(2); liteReflectionShader.SetTextureB(3); liteReflectionShader.SetTextureBlack(0); liteReflectionShader.SetBlendMap(4); liteReflectionShader.SetMaterial(_terrainMaterial); liteReflectionShader.SetTransformationMatrices(ref mirrorMatrix, ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); liteReflectionShader.SetDirectionalLight(Sun); liteReflectionShader.SetClippingPlane(ref clipPlane); _buffer.RenderVAO(PrimitiveType.Triangles); liteReflectionShader.stopProgram(); GL.Disable(EnableCap.ClipDistance0); }
public static void ResolvePostProcessResultToDefaultFramebuffer(ITexture frameTexture, ITexture postProcessResultTexture, Point actualScreenRezolution) { GL.BindFramebuffer(FramebufferTarget.Framebuffer, 0); GL.Clear(ClearBufferMask.DepthBufferBit | ClearBufferMask.ColorBufferBit | ClearBufferMask.StencilBufferBit); GL.Viewport(0, 0, actualScreenRezolution.X, actualScreenRezolution.Y); //GL.Disable(EnableCap.DepthTest); resolvePostProcessShader.startProgram(); frameTexture.BindTexture(TextureUnit.Texture0); postProcessResultTexture.BindTexture(TextureUnit.Texture1); resolvePostProcessShader.setPostProcessResultSampler(1); var quadBuffer = ScreenQuad.GetScreenQuadBuffer(); quadBuffer.RenderVAO(PrimitiveType.Triangles); resolvePostProcessShader.stopProgram(); GL.Enable(EnableCap.DepthTest); }
private void Render(ITexture renderTexture, Int32 index) { PostConstructor(); var texturePixelFormat = renderTexture.GetTextureParameters().TexPixelFormat; bool bDepthTexture = (texturePixelFormat == PixelFormat.DepthComponent || texturePixelFormat == PixelFormat.DepthComponent); var screenSpaceMatrix = GetScreenSpaceMatrix(index); _shader.startProgram(); renderTexture.BindTexture(TextureUnit.Texture0); _shader.SetIsDepthTexture(bDepthTexture); _shader.SetIsSeparatedScreen(false); _shader.SetUiTextureSampler(0); _shader.SetScreenSpaceMatrix(screenSpaceMatrix); _buffer.RenderVAO(PrimitiveType.Triangles); _shader.stopProgram(); }
public override ITexture GetPostProcessResult(ITexture frameColorTexture, ITexture frameDepthTexture, Point actualScreenRezolution, ITexture previousPostProcessResult = null) { postConstructor(); // Rendering bright objects to render target renderTarget.renderToFBO(1, renderTarget.RadialBlurAppliedTexture.GetTextureRezolution()); base.GetPostProcessResult(frameColorTexture, frameDepthTexture, actualScreenRezolution); viewportMatrix = new Matrix4(new Vector4(actualScreenRezolution.X * 0.5f, 0, actualScreenRezolution.X * 0.5f, 0), new Vector4(0, actualScreenRezolution.Y * 0.5f, actualScreenRezolution.Y * 0.5f, 0), new Vector4(0, 0, 1, 0), new Vector4(0, 0, 0, 1)); var radialBlurScreenSpacePosition = getRadialPos(GameWorld.GetWorldInstance().GetLevel().DirectionalLight.Position, GameWorld.GetWorldInstance().GetLevel().Camera.GetViewMatrix(), ref EngineStatics.ProjectionMatrix, ref viewportMatrix); // Render to light shaft result render target renderTarget.renderToFBO(2, renderTarget.LightShaftsResultTexture.GetTextureRezolution()); shader.startProgram(); if (previousPostProcessResult != null) { previousPostProcessResult.BindTexture(TextureUnit.Texture1); shader.SetPreviousPostProcessResultSampler(1); } renderTarget.RadialBlurAppliedTexture.BindTexture(TextureUnit.Texture0); shader.SetBrightPartsTextureSampler(0); shader.SetRadialBlurCenterPositionInScreenSpace(radialBlurScreenSpacePosition); shader.SetRadialBlurExposure(Exposure); shader.SetRadialBlurDecay(Decay); shader.SetRadialBlurDensity(Density); shader.SetRadialBlurNumberOfSamples(NumSamples); shader.SetRadialBlurWeight(Weight); quadBuffer.RenderVAO(PrimitiveType.Triangles); shader.stopProgram(); renderTarget.unbindFramebuffer(); return(renderTarget.LightShaftsResultTexture); }
public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix) { UpdateWorldMatrix(); shader.startProgram(); texture.BindTexture(OpenTK.Graphics.OpenGL.TextureUnit.Texture0); shader.SetDiffuseTexture(0); shader.SetTransformatrionMatrices(WorldMatrix, viewMatrix, projectionMatrix); shader.SetOpacity(1); VAOManager.renderBuffers(rawModel.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles); shader.stopProgram(); foreach (var item in ChildrenComponents) { SceneComponent comp = item as SceneComponent; if (comp != null) { comp.Render(viewMatrix, projectionMatrix); } } }
public void Render(Matrix4 viewMatrix, Matrix4 projectionMatrix) { if (bPostConstructor) { model = new RawModel(attribs); shader = new SkyboxShader(Environment.CurrentDirectory + "/../../Shaders/skyboxVS.glsl", Environment.CurrentDirectory + "/../../Shaders/skyboxFS.glsl"); cubemap = ProxyTextureLoader.LoadCubemap(new string[] { Environment.CurrentDirectory + "/../../Textures/Right.bmp", Environment.CurrentDirectory + "/../../Textures/Left.bmp", Environment.CurrentDirectory + "/../../Textures/top.bmp", Environment.CurrentDirectory + "/../../Textures/bottom.bmp", Environment.CurrentDirectory + "/../../Textures/Back.bmp", Environment.CurrentDirectory + "/../../Textures/Front.bmp" }); bPostConstructor = false; } shader.startProgram(); cubemap.BindTexture(OpenTK.Graphics.OpenGL.TextureUnit.Texture0); shader.SetTransformationMatrices(viewMatrix, projectionMatrix); shader.SetCubemap(0); VAOManager.renderBuffers(model.Buffer, OpenTK.Graphics.OpenGL.PrimitiveType.Triangles); shader.stopProgram(); }
public void renderTerrain(PrimitiveType mode, DirectionalLight directionalLight, List <PointLight> pointLights, BaseCamera camera, Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { PostConstructor(); Matrix4 ModelMatrix = Matrix4.Identity; /*If clip plane is setted - enable clipping plane*/ if (clipPlane.X == 0 && clipPlane.Y == 0 && clipPlane.Z == 0 && clipPlane.W == 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } _shader.startProgram(); _textureBlack.BindTexture(TextureUnit.Texture0); _textureR.BindTexture(TextureUnit.Texture1); _textureG.BindTexture(TextureUnit.Texture2); _textureB.BindTexture(TextureUnit.Texture3); _blendMap.BindTexture(TextureUnit.Texture4); /*For normal mapping local variables*/ Int32 nmR = -1, nmG = -1, nmB = -1, nmBlack = -1; /*TO DO : * if texture exists - bind this texture, and assign temp variable samplers ID, * else - leave temp variable with value -1. */ if (_normalMapR != null) { nmR = 5; _normalMapR.BindTexture(TextureUnit.Texture5); } if (_normalMapG != null) { nmG = 6; _normalMapG.BindTexture(TextureUnit.Texture6); } if (_normalMapB != null) { nmB = 7; _normalMapB.BindTexture(TextureUnit.Texture7); } if (_normalMapBlack != null) { nmBlack = 8; _normalMapBlack.BindTexture(TextureUnit.Texture8); } if (directionalLight != null && directionalLight.GetHasShadow()) { DirectionalLightWithShadow lightWithShadow = directionalLight as DirectionalLightWithShadow; // Get shadow handler ITexture shadowMap = lightWithShadow.GetShadowMapTexture(); shadowMap.BindTexture(TextureUnit.Texture9); // shadowmap _shader.SetDirectionalLightShadowMatrix(lightWithShadow.GetShadowMatrix(ref ModelMatrix, ref ProjectionMatrix)); } _shader.SetTextureR(1, nmR, nmR > 0); _shader.SetTextureG(2, nmG, nmG > 0); _shader.SetTextureB(3, nmB, nmB > 0); _shader.SetTextureBlack(0, nmBlack, nmBlack > 0); _shader.SetBlendMap(4); _shader.SetMaterial(_terrainMaterial); _shader.SetTransformationMatrices(ref ModelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); _shader.SetDirectionalLight(directionalLight); _shader.SetPointLights(pointLights); _shader.SetMist(_mist); _shader.SetClippingPlane(ref clipPlane); _shader.SetDirectionalLightShadowMap(9); _buffer.RenderVAO(mode); _shader.stopProgram(); }
public override ITexture GetPostProcessResult(ITexture frameColorTexture, ITexture frameDepthTexture, Point actualScreenRezolution, ITexture previousPostProcessResult = null) { postConstructor(); /*Extracting bright parts*/ renderTarget.renderToFBO(3, renderTarget.frameTextureLowRezolution.GetTextureRezolution()); base.GetPostProcessResult(frameColorTexture, frameDepthTexture, actualScreenRezolution); renderTarget.renderToFBO(2, renderTarget.horizontalBlurTexture.GetTextureRezolution()); lensShader.startProgram(); renderTarget.frameTextureLowRezolution.BindTexture(TextureUnit.Texture0); lensShader.setUniformValuesThreshold(0, this.threshold); quadBuffer.RenderVAO(PrimitiveType.Triangles); lensShader.stopProgram(); /*Lens effect*/ renderTarget.renderToFBO(1, this.renderTarget.verticalBlurTexture.GetTextureRezolution()); lensShader.startProgram(); renderTarget.horizontalBlurTexture.BindTexture(TextureUnit.Texture0); lensShader.setUniformValuesLens(0, this.Ghosts, this.HaloWidth, this.Distortion, this.GhostDispersal); quadBuffer.RenderVAO(PrimitiveType.Triangles); lensShader.stopProgram(); /*Extra passes for blur*/ for (int i = 0; i < BlurPassCount; i++) { /*Horizontal Blur effect*/ renderTarget.renderToFBO(2, this.renderTarget.horizontalBlurTexture.GetTextureRezolution()); lensShader.startProgram(); renderTarget.verticalBlurTexture.BindTexture(TextureUnit.Texture0); lensShader.setUniformValuesHorizontalBlur(0, normalizedWeights(BlurWidth), getPixOffset(BlurWidth), actualScreenRezolution); quadBuffer.RenderVAO(PrimitiveType.Triangles); lensShader.stopProgram(); /*Vertical Blur effect*/ renderTarget.renderToFBO(1, this.renderTarget.verticalBlurTexture.GetTextureRezolution()); lensShader.startProgram(); renderTarget.horizontalBlurTexture.BindTexture(TextureUnit.Texture0); lensShader.setUniformValuesHorizontalBlur(0, normalizedWeights(BlurWidth), getPixOffset(BlurWidth), actualScreenRezolution); quadBuffer.RenderVAO(PrimitiveType.Triangles); lensShader.stopProgram(); } renderTarget.renderToFBO(4, renderTarget.lensFlareResultTexture.GetTextureRezolution()); lensShader.startProgram(); // If this is one post process stage from many if (previousPostProcessResult != null) { previousPostProcessResult.BindTexture(TextureUnit.Texture1); lensShader.SetPreviousPostProcessResultSampler(1); } renderTarget.verticalBlurTexture.BindTexture(TextureUnit.Texture0); lensShader.setUniformValuesMod(0); quadBuffer.RenderVAO(PrimitiveType.Triangles); lensShader.stopProgram(); renderTarget.unbindFramebuffer(); return(renderTarget.lensFlareResultTexture); }
public override ITexture GetPostProcessResult(ITexture frameColorTexture, ITexture frameDepthTexture, Point actualScreenRezolution, ITexture previousPostProcessResult = null) { PostConstructor(); if (this.blurWidthChanged) { this.blurWeights = normalizedWeights(BlurWidth); this.blurWidthChanged = false; } GL.Disable(EnableCap.DepthTest); renderTarget.renderToFBO(1, renderTarget.VerticalBlurTexture.GetTextureRezolution()); dofShader.startProgram(); frameColorTexture.BindTexture(TextureUnit.Texture0); dofShader.setDownsamplerUniforms(0); quadBuffer.RenderVAO(PrimitiveType.Triangles); dofShader.stopProgram(); /*Gauss blur*/ for (Int32 i = 0; i < BlurPassCount; i++) { /*Horizontal blur of image*/ renderTarget.renderToFBO(2, renderTarget.HorizontalBlurTexture.GetTextureRezolution()); dofShader.startProgram(); renderTarget.VerticalBlurTexture.BindTexture(TextureUnit.Texture0); dofShader.setHorizontalBlurUniforms(0, blurWeights, getPixOffset(BlurWidth), renderTarget.HorizontalBlurTexture.GetTextureRezolution()); quadBuffer.RenderVAO(PrimitiveType.Triangles); dofShader.stopProgram(); /*Vertical blur of image*/ renderTarget.renderToFBO(1, renderTarget.VerticalBlurTexture.GetTextureRezolution()); dofShader.startProgram(); renderTarget.HorizontalBlurTexture.BindTexture(TextureUnit.Texture0); dofShader.setVerticalBlurUniforms(0, blurWeights, getPixOffset(BlurWidth), renderTarget.VerticalBlurTexture.GetTextureRezolution()); quadBuffer.RenderVAO(PrimitiveType.Triangles); dofShader.stopProgram(); } // Blend DoF post process result with previous post process result, if such exists renderTarget.renderToFBO(3, renderTarget.DepthOfFieldResultTexture.GetTextureRezolution()); dofShader.startProgram(); if (previousPostProcessResult != null) { previousPostProcessResult.BindTexture(TextureUnit.Texture2); dofShader.SetPreviousPostProcessResultSampler(2); } else { frameColorTexture.BindTexture(TextureUnit.Texture2); dofShader.SetFrameTextureSampler(2); } renderTarget.VerticalBlurTexture.BindTexture(TextureUnit.Texture0); frameDepthTexture.BindTexture(TextureUnit.Texture1); dofShader.setDoFUniforms(0, 1, BlurStartEdge, BlurEndEdge); quadBuffer.RenderVAO(PrimitiveType.Triangles); dofShader.stopProgram(); renderTarget.unbindFramebuffer(); GL.Enable(EnableCap.DepthTest); return(renderTarget.DepthOfFieldResultTexture); }
public override void renderObject(PrimitiveType mode, DirectionalLight directionalLight, List <PointLight> lights, BaseCamera camera, ref Matrix4 ProjectionMatrix, Vector4 clipPlane = new Vector4()) { postConstructor(); Matrix4 modelMatrix; modelMatrix = GetWorldMatrix(); /*If clip plane is set - enable clipping plane*/ if (clipPlane.X == 0 && clipPlane.Y == 0 && clipPlane.Z == 0 && clipPlane.W == 0) { GL.Disable(EnableCap.ClipDistance0); } else { GL.Enable(EnableCap.ClipDistance0); } GetShader().startProgram(); m_texture.BindTexture(TextureUnit.Texture0); //Bind texture bool bEnableNormalMap = m_normalMap != null; bool bEnableSpecularMap = m_specularMap != null; if (bEnableNormalMap) { m_normalMap.BindTexture(TextureUnit.Texture1); //Bind normal map } if (m_specularMap != null) { m_specularMap.BindTexture(TextureUnit.Texture2); //Bind specular map } GetShader().SetDiffuseMap(0); if (bEnableNormalMap) { GetShader().SetNormalMap(1); } if (bEnableSpecularMap) { GetShader().SetSpecularMap(2); } GetShader().SetMaterial(m_material); GetShader().SetTransformationMatrices(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); GetShader().SetPointLights(GetRelevantPointLights(lights)); GetShader().SetDirectionalLight(directionalLight); GetShader().SetClippingPlane(ref clipPlane); GetShader().SetMist(m_mist); if (directionalLight != null && directionalLight.GetHasShadow()) { DirectionalLightWithShadow lightWithShadow = directionalLight as DirectionalLightWithShadow; ITexture shadowMap = lightWithShadow.GetShadowMapTexture(); shadowMap.BindTexture(TextureUnit.Texture4); // shadowmap GetShader().SetDirectionalLightShadowMatrix(lightWithShadow.GetShadowMatrix(ref modelMatrix, ref ProjectionMatrix)); } GetShader().SetDirectionalLightShadowMap(4); m_skin.Buffer.RenderVAO(mode); GetShader().stopProgram(); /*Show normal for every vertex*/ if (mode == PrimitiveType.Lines) { m_specialShader.startProgram(); m_specialShader.setUniformValues(ref modelMatrix, camera.GetViewMatrix(), ref ProjectionMatrix); m_skin.Buffer.RenderVAO(PrimitiveType.Triangles); m_specialShader.stopProgram(); } }