2014-09-30 17 views
7

मैं एक geomip-mapped इलाके बना रहा हूँ। अब तक मैं काफी अच्छी तरह से काम कर रहा हूँ। कैमरे के पास इलाके का टेस्सेलेशन बहुत अधिक है और कम हो जाता है ताकि ज्यामिति आगे बढ़ सके। इलाके की ज्यामिति अनिवार्य रूप से कैमरे का पालन करती है और शिखर की स्थिति के आधार पर एक ऊंचाई बनावट बना देती है। चूंकि ज्यामिति टेस्सेलेशन बहुत अधिक है, इसलिए आप नमूने के दौरान बनावट में प्रत्येक पिक्सेल को कभी-कभी देख सकते हैं। यह स्पष्ट पिक्सेल टक्कर बनाता है। मैंने सोचा कि मैं ऊंचाई के नमूने को चिकनाई करके इसे पाने में सक्षम हो सकता हूं। हालांकि मुझे कुछ बिलीनेर नमूना कोड से संबंधित एक अजीब समस्या प्रतीत होती है। मैं ऊंचाई चरम बनावट के अनुसार प्रत्येक चरम को विस्थापित करके इलाके को प्रतिपादित कर रहा हूं। किसी दिए गए यूवी पर एक शीर्ष की ऊंचाई प्राप्त करने के लिए समन्वय मैं उपयोग कर सकते हैं:जीएलएसएल वर्टेक्स शेडर बिलीनेर नमूना ऊंचाईमैप

vec2 worldToMapSpace(vec2 worldPosition) { 
    return (worldPosition/worldScale + 0.5); 
} 

float getHeight(vec3 worldPosition) 
{ 
     #ifdef USE_HEIGHTFIELD 
     vec2 heightUv = worldToMapSpace(worldPosition.xz); 
     vec2 tHeightSize = vec2(HEIGHTFIELD_SIZE_WIDTH, HEIGHTFIELD_SIZE_HEIGHT); //both 512 
     vec2 texel = vec2(1.0/tHeightSize); 
     //float coarseHeight = texture2DBilinear(heightfield, heightUv, texel, tHeightSize).r; 
     float coarseHeight = texture2D(heightfield, vUv).r; 
     return altitude * coarseHeight + heightOffset; 
    #else 
     return 0.0; 
    #endif 
} 

कौन सा पैदा करता है यह (ध्यान दें कि किस आप प्रत्येक पिक्सेल देख सकते हैं):

enter image description here

यहाँ एक wireframe है:

enter image description here

मैं इलाके चिकनी नमूना बनाना चाहते थे। तो मैंने सोचा कि मैं मानक बनावट 2 डी फ़ंक्शन के बजाय कुछ बिलीनेर नमूनाकरण का उपयोग कर सकता हूं। तो यहाँ मेरी द्विरेखीय नमूना समारोह है:

vec4 texture2DBilinear(sampler2D textureSampler, vec2 uv, vec2 texelSize, vec2 textureSize) 
{ 
    vec4 tl = texture2D(textureSampler, uv); 
    vec4 tr = texture2D(textureSampler, uv + vec2(texelSize.x, 0.0)); 
    vec4 bl = texture2D(textureSampler, uv + vec2(0.0, texelSize.y)); 
    vec4 br = texture2D(textureSampler, uv + vec2(texelSize.x, texelSize.y)); 
    vec2 f = fract(uv.xy * textureSize); // get the decimal part 
    vec4 tA = mix(tl, tr, f.x); 
    vec4 tB = mix(bl, br, f.x); 
    return mix(tA, tB, f.y); 
} 

texelSize 1/heightmap आकार के रूप में की जाती है:

vec2 texel = vec2(1.0/tHeightSize); 

और textureSize चौड़ाई और heightmap की ऊंचाई है। ? लेकिन, जब मैं इस सुविधा का उपयोग मैं इस परिणाम मिलता है:

float coarseHeight = texture2DBilinear(heightfield, heightUv, texel, tHeightSize).r; 

enter image description here

अब बदतर :(कोई भी विचार लगता है कि मैं गलत क्या कर रहा हो सकता है या फिर कैसे मैं एक चिकनी इलाके नमूने प्राप्त कर सकते हैं

संपादित

यहाँ हालांकि एक ऊर्ध्वाधर स्क्रीनशॉट इलाके पर नीचे देख रहा है। आप परतों ठीक से काम देख सकते हैं। सूचना है कि बाहरी परत कम ट्राईऐन्ग्युलेशंस है और चिकना दिखता है जबकि उच्च tessellation वाले प्रत्येक पिक्सेल दिखाते हैं। मैं बनावट नमूना को सुचारू बनाने के लिए एक रास्ता खोजने की कोशिश कर रहा हूँ।

enter image description here enter image description here

+0

आप पहली जगह में कस्टम बिलीनेर इंटरपोलेशन का उपयोग क्यों कर रहे हैं? यदि प्रत्येक चरम पर ऊंचाई मानचित्र में एक पिक्सेल है तो आपको इसे 'चिकनी' बनाने के लिए बनावट पर गॉस-ब्लर का उपयोग करना चाहिए। यदि आपके पास पिक्सेल की तुलना में अधिक शिखर हैं तो बिल्ड-इन बनावट इंटरपोलेशन काम करेगा। – dari

+0

हाय दारी, मुझे स्पष्टीकरण के लिए मेरे प्रश्न को संपादित करना होगा। इसका कारण यह है कि मैं एक geoclipmapping तकनीक का उपयोग कर रहा हूँ। कैमरे के पास इलाका बहुत ऊंचा है। चूंकि टेस्सेलेशन इतना ऊंचा है, पिक्सल की तुलना में अधिक त्रिकोण हैं। तो यह 1 से 1 अनुपात नहीं है। यानी नमूनाकरण को बेहतर करने की आवश्यकता है, या इसके बजाय इसे पिक्सेल मानों के बीच अंतरण करने की आवश्यकता है। – Mat

+0

और आप इंटरपोलेशन में निर्माण का उपयोग क्यों नहीं कर रहे हैं? https: //www.opengl।संगठन/विकी/Sampler_Object # नमूनाकरण_परमीटर – dari

उत्तर

3

मैं खोजने के लिए और एक तकनीक catmulrom प्रक्षेप का उपयोग करता है को लागू करने में सक्षम था। कोड नीचे है।

// catmull works by specifying 4 control points p0, p1, p2, p3 and a weight. The function is used to calculate a point n between p1 and p2 based 
// on the weight. The weight is normalized, so if it's a value of 0 then the return value will be p1 and if its 1 it will return p2. 
float catmullRom(float p0, float p1, float p2, float p3, float weight) { 
    float weight2 = weight * weight; 
    return 0.5 * (
     p0 * weight * ((2.0 - weight) * weight - 1.0) + 
     p1 * (weight2 * (3.0 * weight - 5.0) + 2.0) + 
     p2 * weight * ((4.0 - 3.0 * weight) * weight + 1.0) + 
     p3 * (weight - 1.0) * weight2); 
} 

// Performs a horizontal catmulrom operation at a given V value. 
float textureCubicU(sampler2D samp, vec2 uv00, float texel, float offsetV, float frac) { 
    return catmullRom(
     texture2DLod(samp, uv00 + vec2(-texel, offsetV), 0.0).r, 
     texture2DLod(samp, uv00 + vec2(0.0, offsetV), 0.0).r, 
     texture2DLod(samp, uv00 + vec2(texel, offsetV), 0.0).r, 
     texture2DLod(samp, uv00 + vec2(texel * 2.0, offsetV), 0.0).r, 
    frac); 
} 

// Samples a texture using a bicubic sampling algorithm. This essentially queries neighbouring 
// pixels to get an average value. 
float textureBicubic(sampler2D samp, vec2 uv00, vec2 texel, vec2 frac) { 
    return catmullRom(
     textureCubicU(samp, uv00, texel.x, -texel.y, frac.x), 
     textureCubicU(samp, uv00, texel.x, 0.0, frac.x), 
     textureCubicU(samp, uv00, texel.x, texel.y, frac.x), 
     textureCubicU(samp, uv00, texel.x, texel.y * 2.0, frac.x), 
    frac.y); 
} 

    // Gets the UV coordinates based on the world X Z position 
    vec2 worldToMapSpace(vec2 worldPosition) { 
     return (worldPosition/worldScale + 0.5); 
    } 


// Gets the height at a location p (world space) 
float getHeight(vec3 worldPosition) 
{ 
    #ifdef USE_HEIGHTFIELD 

     vec2 heightUv = worldToMapSpace(worldPosition.xz); 
     vec2 tHeightSize = vec2(HEIGHTFIELD_WIDTH, HEIGHTFIELD_HEIGHT); 

     // If we increase the smoothness factor, the terrain becomes a lot smoother. 
     // This is because it has the effect of shrinking the texture size and increaing 
     // the texel size. Which means when we do sampling the samples are from farther away - making 
     // it smoother. However this means the terrain looks less like the original heightmap and so 
     // terrain picking goes a bit off. 
     float smoothness = 1.1; 
     tHeightSize /= smoothness; 

     // The size of each texel 
     vec2 texel = vec2(1.0/tHeightSize); 

     // Find the top-left texel we need to sample. 
     vec2 heightUv00 = (floor(heightUv * tHeightSize))/tHeightSize; 

     // Determine the fraction across the 4-texel quad we need to compute. 
     vec2 frac = vec2(heightUv - heightUv00) * tHeightSize; 

     float coarseHeight = textureBicubic(heightfield, heightUv00, texel, frac); 
     return altitude * coarseHeight + heightOffset; 
    #else 
     return 0.0; 
    #endif 
} 
+0

यह उपयोगी है! धन्यवाद। क्या आप परिणाम (छवि) साझा कर सकते हैं? – Nolesh

संबंधित मुद्दे