0

I used a code I found in the internet for effect and it worked perfect but one thing was wrong it blurried my output screen a bit.

What it should be: http://i.imgur.com/5DwEMDR.png

What it is currenty: http://i.imgur.com/tL0HYIM.png

I tried to understand why it's doing it but I couldn't solve it by myself.

First effect class:

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();
  }
}

Second effect class:

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();
  }
}

Edit: I think the problem is there but I can seem to solve it:

sampler colorSampler = sampler_state
{
  Texture = (colorMap);
  AddressU = CLAMP;
  AddressV = CLAMP;
  MagFilter = LINEAR;
  MinFilter = LINEAR;
  Mipfilter = LINEAR;
};
  • If you don't understand what you are doing, then you should take the time to learn, rather than race here for help. You would be doing yourself a lot of good if you went that route. – Evan Apr 30 '14 at 13:38
  • Yes, I started learning HLSL but the problem is I don't know where to fix the problem – user3589439 Apr 30 '14 at 13:48
  • Use systematic trouble shooting approaches. Eliminate singular systems, and pieces of code until you identify what the issue is. Ensure your values are properly passed into the shader. Start with the most trivial of vertex and pixel shaders, a pass through vertex and a simple color sample. Eventually, you will probably notice it is related to your lighting calculations, or texture sampling/filtering settings. – Evan Apr 30 '14 at 13:51
  • #Evan I found the problem using your method but it seems when I change the MagFilter MinFilter and MipFilter to POINT it will render more clearly but with some gaps and some missing pixels.. – user3589439 Apr 30 '14 at 14:32

0 Answers0