2012-09-07 2 views
0

각 프레임을 캡쳐하고 조회 테이블에 따라 각 픽셀의 위치를 ​​변경하려고합니다. 그래서 픽셀 (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++; 
      } 
     } 
    } 

답변

0

에 적용되지 않는 이유는 X를 저장, 볼 수 없습니다 두 개의 텍스쳐 채널 (예 : 적색과 녹색)의 Y 오프셋.

세트 모두 텍스처 같은 그래픽 장치 (XNA 의 렌더 타겟은 질감입니다) : (. 당신이 그것을 사용하는 경우 SpriteBatch이 내부적으로 Texture[0]을 설정 않습니다)

GraphicsDevice.Textures[0] = myRenderTarget; 
GraphicsDevice.Textures[1] = myLookupTable; 

가 셰이더에서

은, 각각의 샘플러를 선언 :

sampler myRenderTarget: register(s0); 
sampler myLookupTable: register(s1); 

가 그런 사를 조절 lookup 테이블을 샘플링하여 렌더 타겟에 mpled 위치를 지정하십시오.

tex2D(myRenderTarget, inTexCoord.xy + tex2D(myLookupTable, inTexCoord.xy).xy); 

위의 HLSL 코드는 테스트하지 않았습니다. 픽셀 좌표에서 오프셋을 사용하고 음수 오프셋을 허용하려면 몇 가지 추가 계산을 제공해야합니다.

+0

답변을 주셔서 감사합니다. 코드를 적용했지만 셰이더가 적용되지 않는 것 같습니다. 문제가있는 곳을 볼 수 있습니까? (SpriteBatch를 사용하지 않아도 3D 모델을 그리는 업데이트 된 코드를 볼 수 있습니다.) – ali

+0

머리 꼭대기에서 나는 잘 모르겠습니다. 아마도 http://gamedev.stackexchange.com/questions/10165/custom-effects-on-model-in-xna이 질문과 답변에 링크 된 블로그 게시물이 도움이 될 수 있습니다. –

관련 문제