public void OnRenderFrame3D(float dt) { if (!_game.GetField <bool>("ShouldRender2DOverlays") || _cameraPathModelRef == null) { return; } var prog = ShaderPrograms.Autocamera; prog.Use(); _platform.CallMethod("GLLineWidth", 2); _platform.CallMethod("BindTexture2d", 0); _game.GlPushMatrix(); _game.GlLoadMatrix(_game.GetField <PlayerCamera>("MainCamera").GetField <double[]>("CameraMatrixOrigin")); var cameraPos = _game.EntityPlayer.CameraPos; _game.GlTranslate( (float)(_origin.X - cameraPos.X), (float)(_origin.Y - cameraPos.Y), (float)(_origin.Z - cameraPos.Z) ); prog.ProjectionMatrix = _game.CurrentProjectionMatrix; prog.ModelViewMatrix = _game.CurrentModelViewMatrix; _platform.CallMethod("RenderMesh", _cameraPathModelRef); _game.GlPopMatrix(); prog.Stop(); }
private void OnRenderSsrChunks() { var ssrFB = _framebuffers[(int)EnumSSRFB.SSR]; if (ssrFB == null) { return; } if (_shaders[(int)EnumSSRShaders.Liquid] == null) { return; } if (!(_textureIdsField.GetValue(_chunkRenderer) is int[] textureIds)) { return; } var playerWaterDepth = _game.playerProperties.EyesInWaterDepth; var playerInWater = playerWaterDepth >= 0.1f; var playerUnderwater = playerInWater ? 0f : 1f; // copy the depth buffer so we can work with it var primaryBuffer = _platform.FrameBuffers[(int)EnumFrameBuffer.Primary]; GL.BindFramebuffer(FramebufferTarget.ReadFramebuffer, primaryBuffer.FboId); GL.BindFramebuffer(FramebufferTarget.DrawFramebuffer, ssrFB.FboId); GL.Clear(ClearBufferMask.DepthBufferBit); GL.BlitFramebuffer(0, 0, primaryBuffer.Width, primaryBuffer.Height, 0, 0, _fbWidth, _fbHeight, ClearBufferMask.DepthBufferBit, BlitFramebufferFilter.Nearest); // bind our framebuffer _platform.LoadFrameBuffer(ssrFB); GL.ClearBuffer(ClearBuffer.Color, 0, new[] { 0f, 0f, 0f, 1f }); GL.ClearBuffer(ClearBuffer.Color, 1, new[] { 0f, 0f, 0f, playerUnderwater }); GL.ClearBuffer(ClearBuffer.Color, 2, new[] { 0f, 0f, 0f, 1f }); if (_refractionsEnabled) { GL.ClearBuffer(ClearBuffer.Color, 3, new [] { 0f, 0f, 0f, 1f }); } _platform.GlEnableCullFace(); _platform.GlDepthMask(true); _platform.GlEnableDepthTest(); _platform.GlToggleBlend(false); var climateAt = _game.BlockAccessor.GetClimateAt(_game.EntityPlayer.Pos.AsBlockPos, EnumGetClimateMode.NowValues); var curRainFall = climateAt.Rainfall; var cameraPos = _game.EntityPlayer.CameraPos; // render stuff _game.GlPushMatrix(); _game.GlLoadMatrix(_mod.CApi.Render.CameraMatrixOrigin); var shader = _shaders[(int)EnumSSRShaders.Opaque]; shader.Use(); shader.UniformMatrix("projectionMatrix", _mod.CApi.Render.CurrentProjectionMatrix); shader.UniformMatrix("modelViewMatrix", _mod.CApi.Render.CurrentModelviewMatrix); shader.Uniform("playerUnderwater", playerUnderwater); var pools = _chunkRenderer.poolsByRenderPass[(int)EnumChunkRenderPass.Opaque]; for (var i = 0; i < textureIds.Length; ++i) { shader.BindTexture2D("terrainTex", textureIds[i], 0); shader.BindTexture2D("terrainTexLinear", textureIds[i], 0); pools[i].Render(cameraPos, "origin"); } shader.Stop(); if (_rainEnabled) { shader = _shaders[(int)EnumSSRShaders.Topsoil]; shader.Use(); shader.UniformMatrix("projectionMatrix", _mod.CApi.Render.CurrentProjectionMatrix); shader.UniformMatrix("modelViewMatrix", _mod.CApi.Render.CurrentModelviewMatrix); shader.Uniform("rainStrength", _currentRain); shader.Uniform("playerUnderwater", playerUnderwater); pools = _chunkRenderer.poolsByRenderPass[(int)EnumChunkRenderPass.TopSoil]; for (var i = 0; i < textureIds.Length; ++i) { shader.BindTexture2D("terrainTex", textureIds[i], 0); pools[i].Render(cameraPos, "origin"); } shader.Stop(); } _platform.GlDisableCullFace(); shader = _shaders[(int)EnumSSRShaders.Liquid]; shader.Use(); shader.UniformMatrix("projectionMatrix", _mod.CApi.Render.CurrentProjectionMatrix); shader.UniformMatrix("modelViewMatrix", _mod.CApi.Render.CurrentModelviewMatrix); shader.Uniform("dropletIntensity", curRainFall); shader.Uniform("waterFlowCounter", _platform.ShaderUniforms.WaterFlowCounter); shader.Uniform("windSpeed", _platform.ShaderUniforms.WindSpeed); shader.Uniform("playerUnderwater", playerUnderwater); shader.Uniform("cameraWorldPosition", _mod.Uniforms.CameraWorldPosition); pools = _chunkRenderer.poolsByRenderPass[(int)EnumChunkRenderPass.Liquid]; for (var i = 0; i < textureIds.Length; ++i) { shader.BindTexture2D("terrainTex", textureIds[i], 0); pools[i].Render(cameraPos, "origin"); } shader.Stop(); _platform.GlEnableCullFace(); shader = _shaders[(int)EnumSSRShaders.Transparent]; shader.Use(); shader.UniformMatrix("projectionMatrix", _mod.CApi.Render.CurrentProjectionMatrix); shader.UniformMatrix("modelViewMatrix", _mod.CApi.Render.CurrentModelviewMatrix); shader.Uniform("playerUnderwater", playerUnderwater); pools = _chunkRenderer.poolsByRenderPass[(int)EnumChunkRenderPass.Transparent]; for (var i = 0; i < textureIds.Length; ++i) { shader.BindTexture2D("terrainTex", textureIds[i], 0); pools[i].Render(cameraPos, "origin"); } shader.Stop(); _game.GlPopMatrix(); _platform.UnloadFrameBuffer(ssrFB); _platform.GlDepthMask(false); _platform.GlToggleBlend(true); _platform.CheckGlError("Error while rendering solid liquids"); }