/// <summary> /// Creates a perspective projection matrix suitable for 2D and 3D rendering. /// /// <para>The first 4 parameters define which area of the stage you want to view (the camera /// will 'zoom' to exactly this region). The final 3 parameters determine the perspective /// in which you're looking at the stage.</para> /// /// <para>The stage is always on the rectangle that is spawned up between x- and y-axis (with /// the given size). All objects that are exactly on that rectangle (z equals zero) will be /// rendered in their true size, without any distortion.</para> /// /// <para>If you pass only the first 4 parameters, the camera will be set up above the center /// of the stage, with a field of view of 1.0 rad.</para> /// </summary> public void SetProjectionMatrix(float x, float y, float width, float height, float stageWidth = 0, float stageHeight = 0, float[] cameraPos = null) { _projectionMatrix3D = MatrixUtil.CreatePerspectiveProjectionMatrix( x, y, width, height, stageWidth, stageHeight, cameraPos); }
/** Does the actual filter processing. This method will be called with up to four input * textures and must return a new texture (acquired from the <code>helper</code>) that * contains the filtered output. To to do this, it configures the FilterEffect * (provided via <code>createEffect</code>) and calls its <code>render</code> method. * * <p>In a standard filter, only <code>input0</code> will contain a texture; that's the * object the filter was applied to, rendered into an appropriately sized texture. * However, filters may also accept multiple textures; that's useful when you need to * combine the output of several filters into one. For example, the DropShadowFilter * uses a BlurFilter to create the shadow and then feeds both input and shadow texture * into a CompositeFilter.</p> * * <p>Never create or dispose any textures manually within this method; instead, get * new textures from the provided helper object, and pass them to the helper when you do * not need them any longer. Ownership of both input textures and returned texture * lies at the caller; only temporary textures should be put into the helper.</p> */ public virtual Texture Process(Painter painter, IFilterHelper helper, Texture input0 = null, Texture input1 = null, Texture input2 = null, Texture input3 = null) { Effect effect = this.Effect; Texture output = helper.GetTexture(_resolution); Matrix3D projectionMatrix; Rectangle bounds = null; Texture renderTarget; if (output != null) // render to texture { renderTarget = output; projectionMatrix = MatrixUtil.CreatePerspectiveProjectionMatrix(0, 0, output.Root.Width / _resolution, output.Root.Height / _resolution); // OpenGL renders into textures with Y coordinates flipped :( projectionMatrix.Flip(output.Height); } else // render to back buffer { bounds = helper.TargetBounds; renderTarget = (helper as FilterHelper).RenderTarget; projectionMatrix = (helper as FilterHelper).ProjectionMatrix3D; effect.TextureSmoothing = _textureSmoothing; } painter.State.RenderTarget = renderTarget; painter.PrepareToDraw(); painter.DrawCount += 1; input0.SetupVertexPositions(VertexData, 0, bounds); input0.SetupTextureCoordinates(VertexData); effect.Texture = input0; effect.MvpMatrix3D = projectionMatrix; effect.UploadVertexData(VertexData); effect.UploadIndexData(IndexData); effect.Render(IndexData.NumTriangles); return(output); }