私の友人は、シェーダーを使用して単純な2Dポイントライトを作成する方法を教えてくれたので、彼の手順に従って、最終的にそれを実行しました。
しかし、何かが起こった、光の形は楕円形のようであり、円のようではありません、私の友人は私に理由を説明できませんでした、
それを修正する方法を教えていただけますか、そしてなぜそれが起こったのか説明していただけますか?
http://dl.dropbox.com/u/2553973/screengrab/PointLight_07.pngのようになります。
ShaderCode
Texture InputTexture;
sampler InputTextureSampler = sampler_state {
texture = <InputTexture>;
magfilter = LINEAR;
minfilter = LINEAR;
mipfilter = LINEAR;
AddressU = mirror;
AddressV = mirror;
};
struct VertexShaderOutput
{
float4 Position : POSITION0;
float2 TexCoord : TEXCOORD0;
float4 Color : COLOR0;
};
float4 ambientColor = float4(1.0,1.0,1.0,0.0);
float ambientIntensity = 0.3f;
float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
//float4 color = float4(1, 0, 0, 1);
float4 texCol = tex2D(InputTextureSampler, input.TexCoord);
float4 color = ambientIntensity*ambientColor;
float dist;
//Light 1
float lightRadius = 0.2f;
float lightIntensity = 15.0f;
float4 lightPos = float4(0.3f,0.3f,0.0f,0);
float4 lightColor = float4(0, 0, 1, 1);
dist = distance(lightPos, input.TexCoord);
color += saturate((lightRadius-dist)*lightIntensity)*lightColor;
texCol = saturate(color) *texCol;
return texCol;
}
technique PointLight
{
pass Pass1
{
PixelShader = compile ps_2_0 PixelShaderFunction();
}
}
XNAコード
GraphicsDevice.SetRenderTarget(normalRender);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin(SpriteSortMode.Immediate, BlendState.AlphaBlend, null, null, null, effectLight);
spriteBatch.Draw(background, Vector2.Zero, Color.White);
spriteBatch.End();
normalRenderTexture = normalRender;
GraphicsDevice.SetRenderTarget(null);
GraphicsDevice.Clear(Color.Black);
spriteBatch.Begin();
spriteBatch.Draw(normalRenderTexture, Vector2.Zero, Color.White);
spriteBatch.End();