簡體   English   中英

如何使我的高度圖更平滑? (柏林噪聲,openGL)

[英]How can I make a smoother my heightmap? (Perlin noise, openGL)

我生成 2D perlin 噪聲並且我正在做地形。 但我有這個問題。 太循序漸進了。

這里是

和多邊形

我試過xz坐標被分割或相乘但不起作用。 如果沒有曲面細分着色器,我該如何解決這個問題?

編輯:

片段着色器代碼:

#version 430

in vec3 pos;
in vec2 text;
in vec3 norm;

layout(binding=3) uniform sampler2D texture_1;
layout(binding=4) uniform sampler2D texture_2;
layout(binding=5) uniform sampler2D texture_3;

vec3 lightPosition = vec3(-200, 700, 50);
vec3 lightAmbient = vec3(0,0,0);
vec3 lightDiffuse = vec3(1,1,1);
vec3 lightSpecular = vec3(1,1,1);

out vec4 fragColor;
vec4 theColor;

void main()
{

    vec3 lightVector = normalize(lightPosition) - normalize(pos); 
    float cosTheta = clamp(dot(normalize(lightVector), normalize(norm)), 0.5, 1.0);

    if(pos.y <= 120){
        fragColor = texture2D(texture_2, text*0.05) * cosTheta;
    }
    if(pos.y > 120 && pos.y  <  150){
        fragColor = (texture2D(texture_2, text*0.05) * (1 - (pos.y-120)/30) +  texture2D(texture_3, text*0.05) * ((pos.y-120)/30))*cosTheta;
    }
    if(pos.y >= 150)
    {
        fragColor = texture2D(texture_3, text*0.05) * cosTheta;
    }
}

頂點着色器代碼:

#version 430

in layout(location=0) vec3 position;
in layout(location=1) vec2 textCoord;
in layout(location=2) vec3 normal;

out vec3 pos;
out vec2 text;
out vec3 norm;


uniform mat4 transformation;

void main()
{   
    gl_Position = transformation * vec4(position, 1.0);
    norm = normal;
    pos = position; 
    text = position.xz;
}

看起來您使用的是 8 位高度圖,它只能為您提供 256 個不同的高度。 您可以嘗試使用 16 位灰度或將高度編碼為 rgb。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM