Я мой друг, научил меня, как сделать простой 2-точечный свет с помощью шейдера, так что я следую его шагам и, наконец, сделал это!
но что-то случилось, светлая форма похожа на овал, а не на круг, мои друзья не могли объяснить, почему,
Не могли бы вы помочь мне, как это исправить, и объясните, почему это произошло?
вот как это выглядит 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 CODE
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();