public override void Render() { Framebuffer.BindWithDrawBuffers(Framebuffer); GL.Enable(EnableCap.Blend); GL.DepthMask(false); Shader.SetShader(PassShader); PassShader.SetupCommonUniforms(); GL.Viewport(0, 0, Screen.Width, Screen.Height); var renderViewData = GlobalGet <RenderViewData>(); foreach (var renderView in renderViewData.RenderViews) { var camera = renderView.camera; var transform = renderView.transform; var viewport = GetViewport(camera); PassShader.SetupCameraUniforms(camera, transform.Position); if (passedTextures != null) { for (int j = 0; j < passedTextures.Length; j++) { var texture = passedTextures[j]; GL.ActiveTexture((TextureUnit)((int)TextureUnit.Texture0 + j)); GL.BindTexture(TextureTarget.Texture2D, texture.Id); if (PassShader != null) { GL.Uniform1(GL.GetUniformLocation(PassShader.Id, texture.Name), j); } } } var vpPointsA = new Vector4( viewport.x / (float)Screen.Width, viewport.y / (float)Screen.Height, viewport.Right / (float)Screen.Width, viewport.Bottom / (float)Screen.Height ); var vpPointsB = vpPointsA * 2f - Vector4.One; DrawUtils.DrawQuadUv0(vpPointsB, vpPointsA); } GL.DepthMask(true); GL.Disable(EnableCap.Blend); }
internal static void Draw(RectFloat rect, Texture texture, Vector4?color = null, GUIStyle style = null) { var vector = new Vector4( rect.x / Screen.Width, rect.y / Screen.Height, (rect.x + rect.width) / Screen.Width, (rect.y + rect.height) / Screen.Height ); if (Shader.ActiveShader.hasDefaultUniform[DefaultShaderUniforms.Color]) { var col = color ?? Vector4.One; GL.Uniform4(Shader.ActiveShader.defaultUniformIndex[DefaultShaderUniforms.Color], col.x, col.y, col.z, col.w); } GL.ActiveTexture(TextureUnit.Texture0); GL.BindTexture(TextureTarget.Texture2D, texture.Id); if (style == null || style.border.left == 0) { DrawUtils.DrawQuadUv0( new Vector4(vector.x, 1f - vector.w, vector.z, 1f - vector.y), new Vector4(0f, 0f, 1f, 1f) ); return; } var textureSize = new Vector2(texture.Width, texture.Height); var center = new Vector4( vector.x + style.border.left / Screen.Width, vector.y + style.border.top / Screen.Height, vector.z - style.border.right / Screen.Width, vector.w - style.border.bottom / Screen.Height ); var centerUV = new Vector4( style.border.left / textureSize.x, style.border.top / textureSize.y, 1f - style.border.right / textureSize.x, 1f - style.border.bottom / textureSize.y ); for (int y = 0; y < 3; y++) { for (int x = 0; x < 3; x++) { Vector4 vertices, uv; switch (x) { default: vertices.x = vector.x; vertices.z = center.x; uv.x = 0f; uv.z = centerUV.x; break; case 1: vertices.x = center.x; vertices.z = center.z; uv.x = centerUV.x; uv.z = centerUV.z; break; case 2: vertices.x = center.z; vertices.z = vector.z; uv.x = centerUV.z; uv.z = 1f; break; } switch (y) { default: vertices.y = 1f - vector.y; vertices.w = 1f - center.y; uv.y = centerUV.y; uv.w = 0f; break; case 1: vertices.y = 1f - center.y; vertices.w = 1f - center.w; uv.y = centerUV.w; uv.w = centerUV.y; break; case 2: vertices.y = 1f - center.w; vertices.w = 1f - vector.w; uv.y = 1f; uv.w = centerUV.w; break; } DrawUtils.DrawQuadUv0(vertices, uv); } } }