C#에서 Managed Direct X 2.0을 사용하고 있으며 RenderToSurface 도우미 클래스를 사용하여 화면을 텍스처로 렌더링하여 만든 텍스처에 프래그먼트 셰이더를 적용하려고합니다.Managed DirectX Postprocessing 프래그먼트 셰이더 렌더링 문제
내가이 일을 사용하고 코드입니다 : 내가 코드를 다음 호출 다음
RenderTexture
라는 텍스처 객체에 부착되어 내 표면, RenderSurface에 렌더링RtsHelper.BeginScene(RenderSurface);
device.Clear(ClearFlags.Target | ClearFlags.ZBuffer, Color.White, 1.0f, 0);
//pre-render shader setup
preProc.Begin(FX.None);
preProc.BeginPass(0);
//mesh drawing
mesh.DrawSubset(j);
preProc.CommitChanges();
preProc.EndPass();
preProc.End();
RtsHelper.EndScene(Filter.None);
렌더링 된 텍스처에 두 번째 셰이더 "PostProc"를 적용하여 화면을 화면에 렌더링합니다. 이 셰이더는 픽셀 단위로 색상 값을 결합하고 장면을 회색 음영으로 변환합니다. 여기 자습서를 다음 해요 : 두 번째 셰이더 텍스처에 렌더링하지만, 수정되지 않은으로
device.BeginScene();
{
using (Sprite sprite = new Sprite(device))
{
sprite.Begin(SpriteFlags.DoNotSaveState);
postProc.Begin(FX.None);
postProc.BeginPass(0);
sprite.Draw(RenderTexture, new Rectangle(0, 0, WINDOWWIDTH, WINDOWHEIGHT), new Vector3(0, 0, 0), new Vector3(0, 0, 0), Color.White);
postProc.CommitChanges();
postProc.EndPass();
postProc.End();
sprite.End();
}
}
device.EndScene();
device.Present();
this.Invalidate();
http://rbwhitaker.wikidot.com/post-processing-effects 그러나 내가 볼 모두가 원래의 렌더링 된 장면입니다.
중요한 점을 대비하여 FX 파일은 다음과 같습니다.
//------------------------------ TEXTURE PROPERTIES ----------------------------
// This is the texture that Sprite will try to set before drawing
texture ScreenTexture;
// Our sampler for the texture, which is just going to be pretty simple
sampler TextureSampler = sampler_state
{
Texture = <ScreenTexture>;
};
//------------------------ PIXEL SHADER ----------------------------------------
// This pixel shader will simply look up the color of the texture at the
// requested point, and turns it into a shade of gray
float4 PixelShaderFunction(float2 TextureCoordinate : TEXCOORD0) : COLOR0
{
float4 color = tex2D(TextureSampler, TextureCoordinate);
float value = (color.r + color.g + color.b)/3;
color.r = value;
color.g = value;
color.b = value;
return color;
}
//-------------------------- TECHNIQUES ----------------------------------------
// This technique is pretty simple - only one pass, and only a pixel shader
technique BlackAndWhite
{
pass Pass1
{
PixelShader = compile ps_1_1 PixelShaderFunction();
}
}