私が達成しようとしているのは次のことです: 私のパスは、CPU で取得して処理する必要がある、いくつかの一意の数字を何度も繰り返す巨大な配列を返します。
2000x1 テクスチャへのレンダリングを試み、RenderTarget2d.GetData<>() と foreach ループを使用して CPU でサンプリングしました。それはひどく遅かった:)。だから私は自分の問題を回避しました。今のアイデアは、1x1 テクスチャに複数回レンダリングすることです。パスの合間に、シェーダーのパラメーター配列を拡張して、既に返された数値を含めます。各ピクセルは、配列を照会し、既に表示されている数値を保持している場合はそれ自体をクリップします。
現在の問題は、何をレンダリングしてもピクセルの色が変わらないことです。常に乱数が返されます。描画呼び出しの前に追加Game.GraphicsDevice.Clear(Color.Transparent);
すると、シェーダー コードは 0.2f (または 0 から 255 に相当) を返す必要がありますが、ゼロが返され始めました。レンダリングするコンテンツが小さすぎて (画面に線を引き、線に沿ってシーンの色をサンプリングしている)、ある時点で lerped が発生する可能性がありますか?
C#/XNA コード:
CollisionRT = new RenderTarget2D(Game.GraphicsDevice, 1, 1, false, SurfaceFormat.Color, DepthFormat.None);
...
Game.GraphicsDevice.BlendState = BlendState.AlphaBlend;
Game.GraphicsDevice.SetRenderTarget(CollisionRT);
Game.GraphicsDevice.Clear(Color.Transparent);
Game.GraphicsDevice.DepthStencilState = DepthStencilState.None;
foreach (ModelMesh mesh in PPCBulletInvis.Model.Meshes)
// PPCBulletInvis is a line that covers 1/18 of the screen (approx).
{
foreach (Effect effect in mesh.Effects)
{
//effect.Parameters["Texture"].SetValue(vfTex);
effect.Parameters["halfPixel"].SetValue(halfPixel);
effect.Parameters["sceneMap"].SetValue(sceneRT);
effect.Parameters["World"].SetValue(testVWall.World);
effect.Parameters["View"].SetValue(camera.View);
effect.Parameters["Projection"].SetValue(camera.Projection);
}
mesh.Draw();
}
Game.GraphicsDevice.SetRenderTarget(null);
Rectangle sourceRectangle =
new Rectangle(0, 0, 1, 1);
Color[] retrievedColor = new Color[1];
CollisionRT.GetData<Color>(retrievedColor);
Console.WriteLine(retrievedColor[0].R); // Returns zeroes.
シェーダー コード:
float4x4 World;
float4x4 View;
float4x4 Projection;
texture sceneMap;
sampler sceneSampler = sampler_state
{
Texture = (sceneMap);
AddressU = CLAMP;
AddressV = CLAMP;
MagFilter = POINT;
MinFilter = POINT;
Mipfilter = POINT;
};
float2 halfPixel;
struct VS_INPUT
{
float4 Position : POSITION0;
};
struct VS_OUTPUT
{
float4 Position : POSITION0;
float4 ScreenPosition : TEXCOORD2;
};
VS_OUTPUT VertexShaderFunction(VS_INPUT input)
{
VS_OUTPUT output;
float4 worldPosition = mul(input.Position, World);
float4 viewPosition = mul(worldPosition, View);
output.Position = mul(viewPosition, Projection);
output.ScreenPosition = output.Position;
return output;
}
float4 PixelShaderFunction(VS_OUTPUT input) : COLOR0
{
input.ScreenPosition.xy /= input.ScreenPosition.w;
float2 screenTexCoord = 0.5f * (float2(input.ScreenPosition.x,-input.ScreenPosition.y) + 1);
screenTexCoord -=halfPixel;
return (0.2f,0.2f,0.2f,0.2f);//tex2D(sceneSampler, screenTexCoord);
}
technique Technique1
{
pass Pass1
{
VertexShader = compile vs_3_0 VertexShaderFunction();
PixelShader = compile ps_3_0 PixelShaderFunction();
}
}