c++ - 我怎样才能使我的高度图更平滑? (柏林噪音,openGL)

标签 c++ opengl shader heightmap

我生成 2D 柏林噪音,我正在做地形。但我对此有疑问。太循序渐进了。

Here it is

And polygon

我试过 x,z 坐标相除或相乘但不起作用。如果没有曲面 segmentation 着色器,我该如何解决这个问题?

编辑:

片段着色器代码:

#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。

关于c++ - 我怎样才能使我的高度图更平滑? (柏林噪音,openGL),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37191378/

相关文章:

c++ - 如何将整数转换为unicode字符?

C++:如何休眠一纳秒?

unity3d - 在unity3d中创建清洁效果

unity3d - unity photosphere - 出现了一条1px的线

c++ - 使用 C 中的 Lua API 覆盖内置类型的运算符

c++ - 如何在运行时指定 priority_queue 的比较器类

c++ - 当启用 msaa 时,gl_FragDepth 是否等于 gl_FragCoord.z?

c++ - 如何在 opengl 中计算给定 3D 点及其 2D 屏幕位置的投影/模型 View 矩阵

opengl - glCreateShader 返回 0

java - 无法渲染简单的顶点数组