private void dilateVelocity(fx_Quad quad, fx_Special special, Texture velocity_texture) { int blur_amount = 150; _pDilate.bind(); GL.Uniform1(_pDilate.getUniform("blur_amount"), blur_amount); GL.Uniform2(_pDilate.getUniform("texture_size"), _tVelocity_1.dimensions.Xy); int fragmentation = 2; //------------------------------------------------------ // Horizontal //------------------------------------------------------ GL.Uniform1(_pDilate.getUniform("direction_selector"), 0); velocity_texture.bind(_pDilate.getSamplerUniform(0), 0); _tVelocity_2.bindImageUnit(_pDilate.getSamplerUniform(1), 1, TextureAccess.WriteOnly); GL.DispatchCompute((int)_tVelocity_1.dimensions.Y, fragmentation, 1); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); //------------------------------------------------------ // Vertical //------------------------------------------------------ GL.Uniform1(_pDilate.getUniform("direction_selector"), 1); _tVelocity_2.bind(_pDilate.getSamplerUniform(0), 0); _tVelocity_1.bindImageUnit(_pDilate.getSamplerUniform(1), 1, TextureAccess.WriteOnly); GL.DispatchCompute((int)_tVelocity_1.dimensions.X, fragmentation, 1); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); }
public void rayTracing(fx_Quad quad, SpatialData camera_spatial) { if (!(_debug_display_voxels && _enabled)) { return; } mipMap(); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pRayTrace.bind(); GL.Uniform1(_pRayTrace.getUniform("vx_volume_dimensions"), _vx_volume_dimensions); Vector3 vx_position_snapped = -voxelSnap(camera_spatial.position); Matrix4 voxel_volume_position = Matrix4.CreateTranslation(vx_position_snapped); Matrix4 invMVP = Matrix4.Invert(_vx_shift_matrix * voxel_volume_position * camera_spatial.model_view * camera_spatial.perspective); GL.UniformMatrix4(_pRayTrace.getUniform("vx_inv_view_perspective"), false, ref invMVP); GL.Uniform1(_pRayTrace.getUniform("displayMipLevel"), _debug_display_voxels_mip_level); _tVoxelVolume.bind(_pRayTrace.getSamplerUniform(0), 0); quad.renderFullQuad(); }
//------------------------------------------------------ // Render //------------------------------------------------------ public void render( fx_Quad quad, Texture normal_texture, Texture diffuse_texture, Texture specular_texture, Vector3 sun_position, Texture shadowDepthTexture) { //------------------------------------------------------ // Render Atmoshpere //------------------------------------------------------ _fAtmosphere.bind(DrawBuffersEnum.ColorAttachment0); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pAtmoshpere.bind(); _tTransmittance.bind(_pAtmoshpere.getUniform("transmittanceSampler"), 0); _tIrradiance.bind(_pAtmoshpere.getUniform("irradianceSampler"), 1); _tInscatter.bind(_pAtmoshpere.getUniform("inscatterSampler"), 2); normal_texture.bind(_pAtmoshpere.getSamplerUniform(0), 3); diffuse_texture.bind(_pAtmoshpere.getSamplerUniform(1), 4); specular_texture.bind(_pAtmoshpere.getSamplerUniform(2), 5); shadowDepthTexture.bind(_pAtmoshpere.getSamplerUniform(3), 6); sun_position = Vector3.Normalize(sun_position); GL.Uniform3(_pAtmoshpere.getUniform("sun_position"), sun_position); quad.renderFullQuad(); }
//------------------------------------------------------ // Depth Of Field //------------------------------------------------------ private void genDOF(fx_Quad quad, Texture depth_texture) { _pDOF_Blur.bind(); GL.Uniform1(_pDOF_Blur.getUniform("max_blur"), _max_blur); GL.Uniform2(_pDOF_Blur.getUniform("texture_size"), _tDOF_Scene.dimensions.Xy); _tCOC_Final.bind(_pDOF_Blur.getSamplerUniform(2), 2); int fragmentation = 2; //------------------------------------------------------ // Horizontal //------------------------------------------------------ GL.Uniform1(_pDOF_Blur.getUniform("direction_selector"), 0); _tDOF_Scene.bind(_pDOF_Blur.getSamplerUniform(0), 0); _tDOF_Scene_2.bindImageUnit(_pDOF_Blur.getSamplerUniform(1), 1, TextureAccess.WriteOnly); GL.DispatchCompute((int)_tDOF_Scene.dimensions.Y, fragmentation, 1); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); //------------------------------------------------------ // Vertical //------------------------------------------------------ GL.Uniform1(_pDOF_Blur.getUniform("direction_selector"), 1); _tDOF_Scene_2.bind(_pDOF_Blur.getSamplerUniform(0), 0); _tDOF_Scene.bindImageUnit(_pDOF_Blur.getSamplerUniform(1), 1, TextureAccess.WriteOnly); GL.DispatchCompute((int)_tDOF_Scene.dimensions.X, fragmentation, 1); GL.MemoryBarrier(MemoryBarrierFlags.ShaderImageAccessBarrierBit); }
private void motionBlur(fx_Quad quad, FrameBuffer scene_fbo, Texture scene_texture, Texture depth_texture, float fps) { GL.Viewport(0, 0, _tFinal.width, _tFinal.height); _pBlur.bind(); GL.Uniform1(_pBlur.getUniform("fps_scaler"), fps); // Velocity Texture _tVelocity_1.bind(_pBlur.getSamplerUniform(1), 1); // Depth Texture depth_texture.bind(_pBlur.getSamplerUniform(2), 2); //------------------------------------------------------ // Pass 1 //------------------------------------------------------ _fFullResolution.bind(DrawBuffersEnum.ColorAttachment0); // Source Texture scene_texture.bind(_pBlur.getSamplerUniform(0), 0); quad.render(); //------------------------------------------------------ // Pass 2 //------------------------------------------------------ scene_fbo.bind(DrawBuffersEnum.ColorAttachment0); // Source Texture _tFinal.bind(_pBlur.getSamplerUniform(0), 0); quad.render(); ////------------------------------------------------------ //// Pass 3 ////------------------------------------------------------ //_fMotionBlur.bind(DrawBuffersEnum.ColorAttachment0); //// Source Texture //scene_texture.bind(_pBlur.getSamplerUniform(0), 0); //quad.render(); ////------------------------------------------------------ //// Pass 4 ////------------------------------------------------------ //scene_fbo.bind(DrawBuffersEnum.ColorAttachment0); //// Source Texture //_tFinal.bind(_pBlur.getSamplerUniform(0), 0); //quad.render(); }
private void blur_Gauss( fx_Quad quad, int blur_amount, Vector2 horizontal_mod, Vector2 vertical_mod, Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement, float destination_scale = 1) { _pBlur_Gauss.bind(); GL.Uniform1(_pBlur_Gauss.getUniform("blur_amount"), blur_amount); Vector2 texture_to_blur_size = new Vector2(texture_to_blur.width, texture_to_blur.height) * destination_scale; Vector2 horizontal_texture_size = new Vector2(1.0f / texture_to_blur_size.X, 1.0f / texture_to_blur_size.Y); Vector2 vertical_texture_size = new Vector2(1.0f / _tSpecial.width, 1.0f / _tSpecial.height); //------------------------------------------------------ // Horizontal //------------------------------------------------------ // Bind special texture and clear it clearAndBindSpecialFrameBuffer(); GL.Viewport(0, 0, (int)texture_to_blur_size.X, (int)texture_to_blur_size.Y); GL.Uniform2(_pBlur_Gauss.getUniform("texture_size"), horizontal_mod * horizontal_texture_size); // Source texture_to_blur.bind(_pBlur_Gauss.getSamplerUniform(0), 0); quad.render(); //------------------------------------------------------ // Vertical //------------------------------------------------------ // If client supplies framebuffer for desintation, use that. Otherwise attach destination to special framebuffer if (texture_frame_buffer.id != _fSpecial.id) { texture_frame_buffer.bind(attachement); } else { bindExternalTexture(texture_to_blur); } GL.Viewport(0, 0, (int)(_tSpecial.width / destination_scale), (int)(_tSpecial.height / destination_scale)); GL.Uniform2(_pBlur_Gauss.getUniform("texture_size"), vertical_mod * vertical_texture_size); // Source _tSpecial.bind(_pBlur_Gauss.getSamplerUniform(0), 0); quad.render(); }
public void render(fx_Quad quad, fx_Special special, Texture scene_texture, FrameBuffer scene_fbo, Matrix4 camera_matrix) { getBrightSpots(quad, scene_texture); genFlare(quad, special); genBloom(quad, special); blend(quad, scene_fbo, camera_matrix); }
//------------------------------------------------------ // Streak Blur Functions //------------------------------------------------------ public void blur_Streak( fx_Quad quad, int blur_amount, float streak_angle, Texture texture_to_blur, float destination_scale = 1) { blur_Streak( quad, blur_amount, streak_angle, texture_to_blur, _fSpecial, DrawBuffersEnum.ColorAttachment1, destination_scale); }
public void blur_Streak( fx_Quad quad, int blur_amount, float streak_angle, Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement, float destination_scale = 1) { _pBlur_Streak.bind(); GL.Uniform1(_pBlur_Streak.getUniform("blur_amount"), blur_amount); Vector2 rotation_vector = EngineHelper.createRotationVector(streak_angle); Vector2 texture_to_blur_size = new Vector2(texture_to_blur.width, texture_to_blur.height) * destination_scale; Vector2 destination_texture_size = new Vector2(1.0f / texture_to_blur_size.X, 1.0f / texture_to_blur_size.Y); Vector2 source_texture_size = new Vector2(1.0f / _tSpecial.width, 1.0f / _tSpecial.height); //------------------------------------------------------ // Iteration 1 //------------------------------------------------------ // Bind special texture and clear it clearAndBindSpecialFrameBuffer(); GL.Viewport(0, 0, (int)texture_to_blur_size.X, (int)texture_to_blur_size.Y); GL.Uniform2(_pBlur_Streak.getUniform("size_and_direction"), rotation_vector * destination_texture_size); GL.Uniform1(_pBlur_Streak.getUniform("iteration"), 0); texture_to_blur.bind(_pBlur_Streak.getSamplerUniform(0), 0); quad.render(); //------------------------------------------------------ // Iteration 2 //------------------------------------------------------ // Bind special texture and clear it if (texture_frame_buffer.id != _fSpecial.id) { texture_frame_buffer.bind(attachement); } else { bindExternalTexture(texture_to_blur); } GL.Viewport(0, 0, (int)(_tSpecial.width / destination_scale), (int)(_tSpecial.height / destination_scale)); GL.Uniform2(_pBlur_Streak.getUniform("size_and_direction"), rotation_vector * source_texture_size); GL.Uniform1(_pBlur_Streak.getUniform("iteration"), 1); _tSpecial.bind(_pBlur_Streak.getSamplerUniform(0), 0); quad.render(); }
public void blur_Gauss( fx_Quad quad, int blur_amount, Texture texture_to_blur, float destination_scale = 1) { blur_Gauss( quad, blur_amount, new Vector2(1.0f, 0.0f), new Vector2(0.0f, 1.0f), texture_to_blur, _fSpecial, DrawBuffersEnum.ColorAttachment1, destination_scale); }
public void render(fx_Quad quad) { GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, 0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pFinalScene.bind(); _tFinalScene.bind(_pFinalScene.getSamplerUniform(0), 0); quad.render(); }
public void blur_Gauss( fx_Quad quad, int blur_amount, Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement, float destination_scale = 1) { blur_Gauss( quad, blur_amount, new Vector2(1.0f, 0.0f), new Vector2(0.0f, 1.0f), texture_to_blur, texture_frame_buffer, attachement, destination_scale); }
private void genBloom(fx_Quad quad, fx_Special special) { // Blur bloom texture at multiple levels of detail and combine for noice effect GL.Enable(EnableCap.Blend); GL.BlendEquation(BlendEquationMode.FuncAdd); GL.BlendFunc(BlendingFactorSrc.One, BlendingFactorDest.One); special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 1); special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 0.5f); special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 0.25f); special.blur_Gauss(quad, 40, _tBloom, _fLens, DrawBuffersEnum.ColorAttachment0, 0.125f); GL.Disable(EnableCap.Blend); }
private void getBrightSpots(fx_Quad quad, Texture scene_texture) { _fLens.bind(DrawBuffersEnum.ColorAttachment0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _tBloom.width, _tBloom.height); _pBrightSpots.bind(); scene_texture.bind(_pBrightSpots.getSamplerUniform(0), 0); quad.render(); _tBloom.generateMipMap(); }
//------------------------------------------------------ // Gaussian Blur Functions //------------------------------------------------------ public void blur_Gauss( fx_Quad quad, int blur_amount, float blur_angle, Texture texture_to_blur, float destination_scale = 1) { Vector2 angle_mod = EngineHelper.createRotationVector(blur_angle); blur_Gauss( quad, blur_amount, angle_mod, angle_mod, texture_to_blur, _fSpecial, DrawBuffersEnum.ColorAttachment1, destination_scale); }
public void render(fx_Quad quad, fx_Special special, Texture depth_texture, FrameBuffer scene_fbo, Texture scene_texture) { autoFocus(depth_texture); //printFocusDistance(); genCOC(quad, special, depth_texture); resetBokeh(); extractBokeh(quad, depth_texture, scene_texture); //printBokehCount(); genBokeh(depth_texture); genDOF(quad, depth_texture); blendDOF(quad, special, scene_fbo, scene_texture); }
public void blur_Gauss( fx_Quad quad, int blur_amount, float blur_angle, Texture texture_to_blur, FrameBuffer texture_frame_buffer, DrawBuffersEnum attachement, float destination_scale = 1) { Vector2 angle_mod = EngineHelper.createRotationVector(blur_angle); blur_Gauss( quad, blur_amount, angle_mod, angle_mod, texture_to_blur, texture_frame_buffer, attachement, destination_scale); }
private void genFlare(fx_Quad quad, fx_Special special) { _fLens.bind(DrawBuffersEnum.ColorAttachment1); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _tFlare.width, _tFlare.height); _pFlare.bind(); _tBloom.bind(_pFlare.getSamplerUniform(0), 0); _iLensColor.bind(_pFlare.getSamplerUniform(1), 1); quad.render(); //special.blur_MovingAverage(15, _tFlare); special.blur_Gauss(quad, 75, _tFlare, _fLens, DrawBuffersEnum.ColorAttachment1); }
public void pass_LightAccumulation(fx_Quad quad, Texture atmoshpere_texture, Texture indirect_texture, FrameBuffer fFinalScene) { fFinalScene.bind(DrawBuffersEnum.ColorAttachment0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pAccumulation.bind(); _tDiffuse_ID.bind(_pAccumulation.getSamplerUniform(0), 0); _tLighting_Diffuse.bind(_pAccumulation.getSamplerUniform(1), 1); _tLighting_Specular.bind(_pAccumulation.getSamplerUniform(2), 2); atmoshpere_texture.bind(_pAccumulation.getSamplerUniform(3), 3); indirect_texture.bind(_pAccumulation.getSamplerUniform(4), 4); quad.render(); }
private void blendDOF(fx_Quad quad, fx_Special special, FrameBuffer scene_fbo, Texture scene_texture) { GL.CopyImageSubData(scene_texture.id, ImageTarget.Texture2D, 0, 0, 0, 0, special.tSpecial.id, ImageTarget.Texture2D, 0, 0, 0, 0, _resolution.W, _resolution.H, 1); scene_fbo.bind(DrawBuffersEnum.ColorAttachment0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pDOF_Blend.bind(); special.tSpecial.bind(_pDOF_Blend.getSamplerUniform(0), 0); _tDOF_Scene.bind(_pDOF_Blend.getSamplerUniform(1), 1); _tCOC_Final.bind(_pDOF_Blend.getSamplerUniform(2), 2); _tBokeh_Points.bind(_pDOF_Blend.getSamplerUniform(3), 3); quad.render(); }
public void scaleScene(fx_Quad quad, FrameBuffer scene_fbo, Texture scene_texture) { // Copy scene texture to temporary texture so we can read and write to main scene texture GL.CopyImageSubData(scene_texture.id, ImageTarget.Texture2D, 0, 0, 0, 0, _tTempScene.id, ImageTarget.Texture2D, 0, 0, 0, 0, _resolution.W, _resolution.H, 1); scene_fbo.bind(DrawBuffersEnum.ColorAttachment0); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pScaleScene.bind(); _tTempScene.bind(_pScaleScene.getSamplerUniform(0), 0); _ssboExposure.bind(0); quad.render(); _ssboExposure.unbind(0); }
public void render(fx_Quad quad, FrameBuffer gbuffer_fbo, Vector3 circadian_position) { // Write into gBuffer's frame buffer attachemnts gbuffer_fbo.bind(new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment3 }); GL.Viewport(0, 0, _resolution.W, _resolution.H); GL.DepthMask(true); GL.Enable(EnableCap.DepthTest); _pSkyBox.bind(); _iSkyBox.bind(_pSkyBox.getSamplerUniform(0), 0); GL.Uniform3(_pSkyBox.getUniform("circadian_position"), Vector3.Normalize(circadian_position)); quad.renderFullQuad(); }
private void blend(fx_Quad quad, FrameBuffer scene_fbo, Matrix4 camera_matrix) { scene_fbo.bind(DrawBuffersEnum.ColorAttachment0); GL.Viewport(0, 0, _resolution.W, _resolution.H); _pBlend.bind(); _iLensDirt.bind(_pBlend.getSamplerUniform(0), 0); _iLensStar.bind(_pBlend.getSamplerUniform(1), 1); _tBloom.bind(_pBlend.getSamplerUniform(2), 2); _tFlare.bind(_pBlend.getSamplerUniform(3), 3); // Lerp the lens star mod so the spin is delayed Matrix3 current_lens_star_mod = getLensStarMod(camera_matrix); Matrix3 lens_star_mod = EngineHelper.lerp(_previous_lens_star_mod, current_lens_star_mod, 0.1f); _previous_lens_star_mod = lens_star_mod; GL.UniformMatrix3(_pBlend.getUniform("lens_star_mod"), true, ref lens_star_mod); quad.renderBlend_Blend(); }
private void extractBokeh(fx_Quad quad, Texture depth_texture, Texture scene_texture) { _fHalfResolution.bind(DrawBuffersEnum.ColorAttachment5); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _tDOF_Scene.width, _tDOF_Scene.height); _pBokeh_Extract.bind(); scene_texture.bind(_pBokeh_Extract.getSamplerUniform(0), 0); depth_texture.bind(_pBokeh_Extract.getSamplerUniform(1), 1); _tCOC_Final.bind(_pBokeh_Extract.getSamplerUniform(2), 2); _tBokeh_Positions.bindImageUnit(_pBokeh_Extract.getSamplerUniform(3), 3, TextureAccess.WriteOnly); _tBokeh_Colors.bindImageUnit(_pBokeh_Extract.getSamplerUniform(4), 4, TextureAccess.WriteOnly); GL.BindBufferRange(BufferRangeTarget.AtomicCounterBuffer, 0, _bokeh_indirect_buffer, (IntPtr)4, (IntPtr)sizeof(uint)); GL.Uniform1(_pBokeh_Extract.getUniform("bokeh_counter"), 0); quad.render(); GL.MemoryBarrier(MemoryBarrierFlags.AllBarrierBits); }
public void coneTracing(fx_Quad quad, Texture diffuse_texture, Texture normal_texture, Texture specular_texture, SpatialData camera_spatial) { if (!_enabled) { _tConeTrace_Diffuse.clear(); return; } mipMap(); _fConeTrace.bind(DrawBuffersEnum.ColorAttachment0); GL.Viewport(0, 0, _tConeTrace_Diffuse.width, _tConeTrace_Diffuse.height); _pConeTrace.bind(); GL.Uniform1(_pConeTrace.getUniform("vx_volume_dimensions"), _vx_volume_dimensions); GL.Uniform1(_pConeTrace.getUniform("vx_volume_scale"), _vx_volume_scale); Vector3 vx_position_snapped = -voxelSnap(camera_spatial.position); Matrix4 voxel_volume_position = Matrix4.CreateTranslation(vx_position_snapped); GL.Uniform3(_pConeTrace.getUniform("vx_volume_position"), vx_position_snapped); GL.Uniform1(_pConeTrace.getUniform("maxMipLevels"), _tVoxelVolume.getMaxMipMap()); normal_texture.bind(_pConeTrace.getSamplerUniform(0), 0); specular_texture.bind(_pConeTrace.getSamplerUniform(1), 1); diffuse_texture.bind(_pConeTrace.getSamplerUniform(2), 2); _tVoxelVolume.bind(_pConeTrace.getSamplerUniform(3), 3); quad.renderFullQuad(); }
public void render(fx_Quad quad, fx_Special special, FrameBuffer scene_fbo, Texture scene_texture, Texture depth_texture, Texture velocity_texture, float fps) { dilateVelocity(quad, special, velocity_texture); motionBlur(quad, scene_fbo, scene_texture, depth_texture, fps); }
public void render(fx_Quad quad) { }
//------------------------------------------------------ // COC //------------------------------------------------------ private void genCOC(fx_Quad quad, fx_Special special, Texture depth_texture) { //------------------------------------------------------ // Calculate COC //------------------------------------------------------ _fHalfResolution.bind(new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1, DrawBuffersEnum.ColorAttachment2 }); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _tCOC.width, _tCOC.height); _pCOC.bind(); _ssboAutoFocus.bind(0); depth_texture.bind(_pCOC.getSamplerUniform(0), 0); GL.Uniform1(_pCOC.getUniform("PPM"), _PPM); GL.Uniform1(_pCOC.getUniform("focus_length"), _focus_length); GL.Uniform1(_pCOC.getUniform("fStop"), _fStop); GL.Uniform1(_pCOC.getUniform("max_blur"), _max_blur); quad.render(); special.blur_Gauss(quad, 60, _tCOC_Foreground_Blurred, _fHalfResolution, DrawBuffersEnum.ColorAttachment1); //------------------------------------------------------ // Fix COC //------------------------------------------------------ _fHalfResolution.bind(new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment3, }); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _tCOC.width, _tCOC.height); _pCOC_Fix.bind(); _tCOC_Foreground.bind(_pCOC_Fix.getSamplerUniform(0), 0); _tCOC_Foreground_Blurred.bind(_pCOC_Fix.getSamplerUniform(1), 1); quad.render(); special.blur_Gauss(quad, 10, _tCOC_Foreground_Final, _fHalfResolution, DrawBuffersEnum.ColorAttachment3); //------------------------------------------------------ // Combine COC //------------------------------------------------------ _fFullResoution.bind(new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, }); GL.Clear(ClearBufferMask.ColorBufferBit); GL.Viewport(0, 0, _tCOC_Final.width, _tCOC_Final.height); _pCOC_Combine.bind(); _tCOC.bind(_pCOC_Combine.getSamplerUniform(0), 0); _tCOC_Foreground_Final.bind(_pCOC_Combine.getSamplerUniform(1), 1); quad.render(); }
public void precompute(fx_Quad quad) { if (_precomputed) { return; } _fPrecompute.bind(DrawBuffersEnum.ColorAttachment0); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tTransmittance.id); GL.Viewport(0, 0, TRANSMITTANCE_W, TRANSMITTANCE_H); _pTransmittance.bind(); quad.render(); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaE.id); GL.Viewport(0, 0, SKY_W, SKY_H); _pIrradiance1.bind(); _tTransmittance.bind(_pIrradiance1.getUniform("transmittanceSampler"), 0); quad.render(); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaSR.id); _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment1, _tDeltaSM.id); _fPrecompute.bindAttachements(new DrawBuffersEnum[] { DrawBuffersEnum.ColorAttachment0, DrawBuffersEnum.ColorAttachment1 }); GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU); _pInscatter1.bind(); _tTransmittance.bind(_pInscatter1.getUniform("transmittanceSampler"), 0); for (int layer = 0; layer < RES_R; layer++) { setLayer(_pInscatter1, layer); quad.render(); } _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment1, 0); _fPrecompute.bindAttachements(DrawBuffersEnum.ColorAttachment0); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tIrradiance.id); GL.Viewport(0, 0, SKY_W, SKY_H); _pCopyIrradiance.bind(); GL.Uniform1(_pCopyIrradiance.getUniform("k"), 0f); _tDeltaE.bind(_pCopyIrradiance.getUniform("deltaESampler"), 0); quad.render(); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tInscatter.id); GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU); _pCopyInscatter1.bind(); _tDeltaSR.bind(_pCopyInscatter1.getUniform("deltaSRSampler"), 0); _tDeltaSM.bind(_pCopyInscatter1.getUniform("deltaSMSampler"), 1); for (int layer = 0; layer < RES_R; layer++) { setLayer(_pCopyInscatter1, layer); quad.render(); } //------------------------------------------------------ for (int order = 2; order <= 4; order++) { //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaJ.id); GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU); _pPJ.bind(); GL.Uniform1(_pPJ.getUniform("first"), order == 2 ? 1f : 0f); _tTransmittance.bind(_pPJ.getUniform("transmittanceSampler"), 0); _tDeltaE.bind(_pPJ.getUniform("deltaESampler"), 1); _tDeltaSR.bind(_pPJ.getUniform("deltaSRSampler"), 2); _tDeltaSM.bind(_pPJ.getUniform("deltaSMSampler"), 3); for (int layer = 0; layer < RES_R; layer++) { setLayer(_pPJ, layer); quad.render(); } //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaE.id); GL.Viewport(0, 0, SKY_W, SKY_H); _pIrradianceN.bind(); GL.Uniform1(_pIrradianceN.getUniform("first"), order == 2 ? 1f : 0f); _tTransmittance.bind(_pIrradianceN.getUniform("transmittanceSampler"), 0); _tDeltaE.bind(_pIrradianceN.getUniform("deltaESampler"), 1); _tDeltaSR.bind(_pIrradianceN.getUniform("deltaSRSampler"), 2); _tDeltaSM.bind(_pIrradianceN.getUniform("deltaSMSampler"), 3); quad.render(); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tDeltaSR.id); GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU); _pInscatterN.bind(); GL.Uniform1(_pInscatterN.getUniform("first"), order == 2 ? 1f : 0f); _tTransmittance.bind(_pInscatterN.getUniform("transmittanceSampler"), 0); _tDeltaJ.bind(_pInscatterN.getUniform("deltaJSampler"), 1); for (int layer = 0; layer < RES_R; layer++) { setLayer(_pInscatterN, layer); quad.render(); } //------------------------------------------------------ //------------------------------------------------------ GL.Enable(EnableCap.Blend); GL.BlendEquationSeparate(BlendEquationMode.FuncAdd, BlendEquationMode.FuncAdd); GL.BlendFuncSeparate(BlendingFactorSrc.One, BlendingFactorDest.One, BlendingFactorSrc.One, BlendingFactorDest.One); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tIrradiance.id); GL.Viewport(0, 0, SKY_W, SKY_H); _pCopyIrradiance.bind(); GL.Uniform1(_pCopyIrradiance.getUniform("k"), 1f); _tDeltaE.bind(_pCopyIrradiance.getUniform("deltaESampler"), 0); quad.render(); //------------------------------------------------------ _fPrecompute.bindTexture(FramebufferAttachment.ColorAttachment0, _tInscatter.id); GL.Viewport(0, 0, RES_MU_S * RES_NU, RES_MU); _pCopyInscatterN.bind(); _tDeltaSR.bind(_pCopyInscatterN.getUniform("deltaSRSampler"), 0); for (int layer = 0; layer < RES_R; layer++) { setLayer(_pCopyInscatterN, layer); quad.render(); } //------------------------------------------------------ GL.Disable(EnableCap.Blend); //------------------------------------------------------ //------------------------------------------------------ } _precomputed = true; }