hlsl输出模糊图像

时间:2014-04-30 13:29:25

标签: c# xna hlsl

我使用了我在互联网上找到的代码,效果很好但是有一点是错的,它使我的输出屏幕变得模糊不清。

应该是什么:http://i.imgur.com/5DwEMDR.png

当前的情况:http://i.imgur.com/tL0HYIM.png

我试着明白为什么要这样做,但我自己无法解决。

第一个效果类:

const float3 black = float3(0.0f, 0.0f, 0.0f);

float2 lightSource;
float3 lightColor;
float  lightRadius;

struct VertexShaderInput
{
  float3 Position : POSITION0;
  float2 TexCoord : TEXCOORD0;
};

struct VertexShaderOutput
{
  float4 Position : POSITION0;
  float2 WorldPos : TEXCOORD0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
  VertexShaderOutput output;
  output.Position = float4(input.Position, 1);
  output.WorldPos = input.TexCoord;
  return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
  float2 position = input.WorldPos - lightSource;     
  float dist = sqrt(dot(position, position));

  float3 mix = lerp(lightColor, black, saturate(dist / lightRadius));
  return float4(mix, 1.0f);
}

technique Technique1
{
  pass Pass1
  {
    VertexShader = compile vs_2_0 VertexShaderFunction();
    PixelShader = compile ps_2_0 PixelShaderFunction();
  }
}

第二效果类:

texture colorMap;
texture lightMap;

sampler colorSampler = sampler_state
{
  Texture = (colorMap);
  AddressU = CLAMP;
  AddressV = CLAMP;
  MagFilter = LINEAR;
  MinFilter = LINEAR;
  Mipfilter = LINEAR;
};
sampler lightSampler = sampler_state
{
  Texture = (lightMap);
  AddressU = CLAMP;
  AddressV = CLAMP;
  MagFilter = LINEAR;
  MinFilter = LINEAR;
  Mipfilter = LINEAR;
};

struct VertexShaderInput
{
  float3 Position : POSITION0;
  float2 TexCoord : TEXCOORD0;
};

struct VertexShaderOutput
{
  float4 Position : POSITION0;
  float2 TexCoord : TEXCOORD0;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
  VertexShaderOutput output;
  output.Position = float4(input.Position, 1);
  output.TexCoord = input.TexCoord;
  return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
  float3 diffuseColor = tex2D(colorSampler, input.TexCoord).rgb;
  float3 light = tex2D(lightSampler, input.TexCoord).rgb;   
  return float4((diffuseColor * light), 1);  
}

technique Technique1
{
  pass Pass1
  {
    VertexShader = compile vs_2_0 VertexShaderFunction();
    PixelShader = compile ps_2_0 PixelShaderFunction();
  }
}

编辑: 我认为问题存在,但我似乎可以解决它:

sampler colorSampler = sampler_state
{
  Texture = (colorMap);
  AddressU = CLAMP;
  AddressV = CLAMP;
  MagFilter = LINEAR;
  MinFilter = LINEAR;
  Mipfilter = LINEAR;
};

0 个答案:

没有答案