我想捕获每一帧并根据查找表更改每个像素的位置。例如像素 (30,35) -> (40,50) 等等。
所以我所做的是通过 RenderTarget2D 捕获一帧并遍历每个像素并在新的位图数组中设置每个像素的新位置。但是由于 RenderTarget2D.GetColor 方法的影响,这降低了性能。
所以我认为Pixel Shader可能是解决方案:在Draw方法中:1.绘制一个简单的框架2.通过RenderTarget2D捕获它3.然后通过着色器绘制模型
但是在着色器内部,我需要访问刚刚捕获的 Texture2D 以及查找表以读取映射的像素位置。如何将这些变量传递给着色器?
编辑:这是 Draw() 方法中的代码,但我看不出为什么没有对模型应用任何更改
protected override void Draw(GameTime gameTime)
{
GraphicsDevice.Textures[0] = ShaderRenderTarget;
GraphicsDevice.Textures[1] = LookupTexture;
// Change to our offscreen render target.
GraphicsDevice.SetRenderTarget(ShaderRenderTarget);
// Render a simple scene.
DrawAFrame();
// Change back to the back buffer, and get our scene
// as a texture.
GraphicsDevice.SetRenderTarget(null);
waldramEffect.CurrentTechnique = waldramEffect.Techniques["Waldraam"];
// Use Immediate mode and our effect to draw the scene
// again, using our pixel shader.
GraphicsDevice.Clear(Color.CornflowerBlue);
CreateViewMatrix();
// Copy any parent transforms.
Matrix[] transforms = new Matrix[myModel.Bones.Count];
myModel.CopyAbsoluteBoneTransformsTo(transforms);
// Draw the model. A model can have multiple meshes, so loop.
foreach (ModelMesh mesh in myModel.Meshes)
{
// This is where the mesh orientation is set, as well
// as our camera and projection.
foreach (ModelMeshPart part in mesh.MeshParts)
{
part.Effect = waldramEffect;
waldramEffect.Parameters["World"].SetValue(Matrix.CreateRotationY(modelRotation) * Matrix.CreateTranslation(modelPosition));
waldramEffect.Parameters["View"].SetValue(lookAt);
waldramEffect.Parameters["Projection"].SetValue(projection);
}
// Draw the mesh, using the effects set above.
mesh.Draw();
}
base.Draw(gameTime);
int i = 0;
foreach (ModelMesh mesh in myModel.Meshes)
{
foreach (ModelMeshPart part in mesh.MeshParts)
{
part.Effect = basicEffects[i];
i++;
}
}
}