Search code examples
hlslfragment-shaderantialiasinguv-mapping

how do i set UV coordination from Texture value without noise in HLSL


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

Solution

  • 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