각 프레임을 캡쳐하고 조회 테이블에 따라 각 픽셀의 위치를 변경하려고합니다. 그래서 픽셀 (30,35) -> (40,50) 등등.Texture2D 개체를 XNA 4.0의 Pixel Shader로 전달하는 방법은 무엇입니까?
그래서 내가 한 것은 RenderTarget2D로 프레임을 캡쳐하고 각 픽셀을 살펴보고 새 비트 맵 배열에 각 픽셀의 새 위치를 설정하는 것입니다. 그러나 RenderTarget2D.GetColor 메서드의 효과로 인해 성능이 저하되었습니다. 그리기 방법 :
은 그래서 픽셀 쉐이더가 해결책이 될 거라고 생각 이 1.draw RenderTarget2D 하여 간단한 프레임 2.capture 그것은 3.and는 다음 쉐이더를하여 모델을 그릴그러나 셰이더 내부에서 방금 캡쳐 된 Texture2D와 매핑 된 픽셀 위치를 읽는 조회 테이블에 액세스해야합니다. 어떻게 이러한 변수를 셰이더에 전달할 수 있습니까?
편집
: 이 그리기() 메소드에있는 코드이지만, 변화가 질감으로 조회 테이블을 확인 모델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++;
}
}
}
답변을 주셔서 감사합니다. 코드를 적용했지만 셰이더가 적용되지 않는 것 같습니다. 문제가있는 곳을 볼 수 있습니까? (SpriteBatch를 사용하지 않아도 3D 모델을 그리는 업데이트 된 코드를 볼 수 있습니다.) – ali
머리 꼭대기에서 나는 잘 모르겠습니다. 아마도 http://gamedev.stackexchange.com/questions/10165/custom-effects-on-model-in-xna이 질문과 답변에 링크 된 블로그 게시물이 도움이 될 수 있습니다. –