मैं अगले कोड का उपयोग कर Unity3D का स्वत: द्विरेखीय छानने एल्गोरिथ्म को दोहराने के लिए कोशिश कर रहा हूँ:बिलीनेर फ़िल्टरिंग नहीं होने पर यह तकनीक क्या है?
fixed4 GetBilinearFilteredColor(float2 texcoord)
{
fixed4 s1 = SampleSpriteTexture(texcoord + float2(0.0, _MainTex_TexelSize.y));
fixed4 s2 = SampleSpriteTexture(texcoord + float2(_MainTex_TexelSize.x, 0.0));
fixed4 s3 = SampleSpriteTexture(texcoord + float2(_MainTex_TexelSize.x, _MainTex_TexelSize.y));
fixed4 s4 = SampleSpriteTexture(texcoord);
float2 TexturePosition = float2(texcoord)* _MainTex_TexelSize.z;
float fu = frac(TexturePosition.x);
float fv = frac(TexturePosition.y);
float4 tmp1 = lerp(s4, s2, fu);
float4 tmp2 = lerp(s1, s3, fu);
return lerp(tmp1, tmp2, fv);
}
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = GetBilinearFilteredColor(IN.texcoord) * IN.color;
c.rgb *= c.a;
return c;
}
मैंने सोचा कि मैं सही एल्गोरिथ्म उपयोग कर रहा था क्योंकि केवल एक ही मैं द्विरेखीय के लिए वहाँ बाहर देखा है।
- 1º बनावट: है प्वाइंट छानने में और कस्टम द्विरेखीय शेडर (डिफ़ॉल्ट स्प्राइट शेडर से maded) का उपयोग लेकिन मैं इसे एक ही बनावट दोहराया के साथ एकता उपयोग करने की कोशिश।
- 2º बनावट: डिफ़ॉल्ट स्प्राइट शेडर
साथ द्विरेखीय फिल्टर में है और यह परिणाम है:
आपको लगता है कि वे अलग हैं देख सकते हैं और यह भी वहाँ कुछ है मेरे कस्टम शेडर में विस्थापन जो ज़ेड अक्ष में घूमते समय स्प्राइट ऑफ-सेंटर बनता है।
क्या मैं गलत कर रहा हूं इसका कोई विचार? यूनिटी 3 डी क्या कर रहा है इसके बारे में कोई विचार? क्या कोई और एल्गोरिदम है जो यूनिटी 3 डी डिफ़ॉल्ट फ़िल्टरिंग में फिट बैठता है?
समाधान
अन्य लोगों को जो यहाँ इसके लिए खोज के लिए निको के कोड के साथ पूरा कोड समाधान के साथ अपडेट किया गया:
fixed4 GetBilinearFilteredColor(float2 texcoord)
{
fixed4 s1 = SampleSpriteTexture(texcoord + float2(0.0, _MainTex_TexelSize.y));
fixed4 s2 = SampleSpriteTexture(texcoord + float2(_MainTex_TexelSize.x, 0.0));
fixed4 s3 = SampleSpriteTexture(texcoord + float2(_MainTex_TexelSize.x, _MainTex_TexelSize.y));
fixed4 s4 = SampleSpriteTexture(texcoord);
float2 TexturePosition = float2(texcoord)* _MainTex_TexelSize.z;
float fu = frac(TexturePosition.x);
float fv = frac(TexturePosition.y);
float4 tmp1 = lerp(s4, s2, fu);
float4 tmp2 = lerp(s1, s3, fu);
return lerp(tmp1, tmp2, fv);
}
fixed4 frag(v2f IN) : SV_Target
{
fixed4 c = GetBilinearFilteredColor(IN.texcoord - 0.498 * _MainTex_TexelSize.xy) * IN.color;
c.rgb *= c.a;
return c;
}
और परिणाम के साथ छवि परीक्षण:
0.5 बिल्कुल ठीक क्यों नहीं करते?
यदि आप इसका परीक्षण करते हैं तो आप कुछ किनारे के मामलों को देखेंगे जहां यह (पिक्सेल -1) तक कूदता है।