-1

i have UV render pass ( RG image )
enter image description here
i want to set the uv pass texture value to UV Coordinate without noise when i test it the result should pixlate noise like the below image
enter image description here

i have tested it in other shader languages like cgprogramm and GLSL
also test it in unity
and try using Zdepth for mipmap but i cant get anti aliased result
all the results are the same

float4x4 World;
float4x4 View;
float4x4 Projection;
float4x4 WorldInverseTranspose;

float4 AmbientColor = float4(1, 1, 1, 1);
float AmbientIntensity = 0.1;

float3 DiffuseLightDirection = float3(1, 0, 0);
float4 DiffuseColor = float4(1, 1, 1, 1);
float DiffuseIntensity = 1.0;

float Shininess = 200;
float4 SpecularColor = float4(1, 1, 1, 1);
float SpecularIntensity = 1;
float3 ViewVector = float3(1, 0, 0);

texture ModelTexture;
texture UvTexture;
sampler2D textureSampler = sampler_state {
    Texture = (ModelTexture);
    MinFilter = Point;
    MagFilter = Point;
    AddressU = Wrap;
    AddressV = Wrap;
};
sampler2D textureSamplerUV = sampler_state {
    Texture = (UvTexture);
    MinFilter = Linear;
    MagFilter = Linear;
    AddressU = Clamp;
    AddressV = Clamp;
};
struct VertexShaderInput
{
    float4 Position : POSITION0;
    float4 Normal : NORMAL0;
    float2 TextureCoordinate : TEXCOORD0;

};

struct VertexShaderOutput
{
    float4 Position : POSITION0;
    float2 Color : COLOR0;
    float3 Normal : TEXCOORD0;
    float2 TextureCoordinate : TEXCOORD1;
};

VertexShaderOutput VertexShaderFunction(VertexShaderInput input)
{
    VertexShaderOutput output;

    float4 worldPosition = mul(input.Position, World);
    float4 viewPosition = mul(worldPosition, View);
    output.Position = mul(viewPosition, Projection);

    float4 normal = normalize(mul(input.Normal, WorldInverseTranspose));
    float lightIntensity = dot(normal, DiffuseLightDirection);
    output.Color = saturate(DiffuseColor * DiffuseIntensity * lightIntensity);

    output.Normal = normal;

    output.TextureCoordinate = input.TextureCoordinate;
    return output;
}

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    //******* is here 
    float4 textureColorUV = tex2D(textureSamplerUV, input.TextureCoordinate);

    float2 cord = float2(textureColorUV[0],textureColorUV[1]);

    float4 textureColor = tex2D(textureSampler, cord);

    return saturate(textureColor);
}

technique Textured
{
    pass Pass1
    {
        VertexShader = compile vs_1_1 VertexShaderFunction();
        PixelShader = compile ps_2_0 PixelShaderFunction();
    }
}
ehsan wwe
  • 71
  • 2
  • 9

2 Answers2

1

It is not noise, it is point sampling. Min and Mag should be Linear. and Mip should be Point ( bi linear ) or Linear ( tri linear ) to make use of mipmaps

As a side note, You could use point sampling for the uv texture to get proper values on edges, bu you don't have to use point sampler here, they may be slower than regular filtering on modern hardware. You can of course make sure that the texcoord you generate for the texture fetch is well aligned, but you have a simpler solution if you have access to DX11.

The simplest if i was writing your shader would be to use SV_Position in the pixel shader with the bracket operator :

float4 PixelShaderFunction(VertexShaderOutput input) : COLOR0
{
    //******* 
    float2 uv = textureSamplerUV[input.Position].rg;    

    float4 textureColor = texture.Sample( sampler, uv );    
    return (textureColor); // unless you use a non unorm format, saturate not necessary.
}
galop1n
  • 8,573
  • 22
  • 36
  • thanx galop but when i want to try i have error with Position :( and .rg – ehsan wwe May 03 '17 at 10:34
  • @ehsanwwe it is because you are using very old shader models, 1.1 and 2.0. Unless you try to support antediluvian hardware and you or are not in DX11, you can't do that. Your original shader code works if you just fix the sampler state. – galop1n May 03 '17 at 16:54
  • thanx for helping but i try it i use DX11 in Unity shader - but the result is the same - i replace input.position with my object UV ( plane object 0,0 1,0 ,11 , 1,0 ) :( i think mip filtering didn't work in pixle uv just work with vector uv - my comment is true ? – ehsan wwe May 03 '17 at 18:55
-1

i find whats reason of the noise
My uv image is an normal byte image R(255)G(255)B(255)
and the Texture W and H split to just 255 raw and columns and is not enough - it's main reason to see the noise

i replace my UV image to 16Bit image and solve the problem
my new UV image split texture to 65535 raw and columns enter image description here

ehsan wwe
  • 71
  • 2
  • 9