2017-05-02 45 views
-1

置紫外光協調從紋理值,無噪音,我有UV渲染通道(RG圖像)
enter image description here
我想設置的UV過程紋理值進行UV座標無噪音 當我測試它的結果應該pixlate噪音像下面的圖片
enter image description here我如何在HLSL

我已經在其他着色器語言,如cgprogramm和GLSL
測試它 也測試團結
並嘗試使用Zdepth的紋理貼圖,但我不能讓反鋸齒RESU LT
所有的結果都是一樣的

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

回答

-1

我找到什麼噪音
我的紫外圖像的原因是正常的字節圖像R(255)G(255)B(255)
和紋理W和H被劃分到剛剛255原料和列是不夠的 - 它的主要理由看噪聲

我代替我的UV圖像16位圖像並解決問題
我的新的UV圖像分割紋理65535原料和列 enter image description here

1

這不是噪聲,它是點採樣。 Min和Mag應該是線性的。和Mip應該是點(雙線性)或線性(三線性)以使用mipmapps

作爲一個方面說明,您可以使用uv紋理的點採樣來獲得邊緣上的適當值,必須在這裏使用點採樣器,它們可能比現代硬件上的常規過濾要慢。您當然可以確保您爲紋理獲取生成的texcoord對齊良好,但如果您有權訪問DX11,則可以使用更簡單的解決方案。

最簡單的,如果我是寫你的着色器將在像素着色器使用SV_Position與支架操作:

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. 
} 
+0

感謝名單GALOP但是當我想試試我有誤差的位置:(和.rg –

+0

@ehsanwwe那是因爲你使用的是很舊的着色模式的,1.1和2.0。除非您嘗試支持以前的硬件,並且您或不在DX11中,否則不能這樣做。如果您只是修正採樣器狀態,則原始着色器代碼將起作用。 – galop1n

+0

thanx幫助,但我嘗試它我在Unity着色器中使用DX11 - 但結果是相同的 - 我用我的對象替換input.position紫外線(平面對象0,0 1,0,11,1,0):(我認爲MIP過濾不適用於像素紫外線只是與矢量紫外線 - 我的評論是真的嗎? –