简体   繁体   English

投影网格水位细节

[英]Projected grid water horizon detail

I'm trying to implement an ocean scene with C++ and DirectX11.我正在尝试使用 C++ 和 DirectX11 实现海洋场景。 Currently I have a projected grid, Gerstner waves and a basic shading.目前我有一个投影网格、Gerstner 波和一个基本的阴影。 My problem is that when I aim my camera horizontally, so I can see the water horizon, in the distance, the projected grid becomes insufficient, even at high vertex numbers.我的问题是,当我水平瞄准我的相机时,我可以看到远处的水面,即使在高顶点数的情况下,投影网格也变得不足。 These screenshots illustrate the problem:这些屏幕截图说明了问题:

阴影水面

线框水面

I know the cause of the problem is in the concept of the projected grid (the grid is detailed near the camera, rough far from it), but there has to be a best practice to solve this.我知道问题的原因在于投影网格的概念(网格在相机附近很详细,远离它很粗糙),但必须有一个最佳实践来解决这个问题。

Any ideas?有任何想法吗?

Benedikt Bitterli and joojaa answered my question here: https://computergraphics.stackexchange.com/questions/1681/projected-grid-water-horizon-detail Benedikt Bitterli 和 joojaa 在这里回答了我的问题: https ://computergraphics.stackexchange.com/questions/1681/projected-grid-water-horizo​​n-detail

I chose the laziest solution for now.我现在选择了最懒惰的解决方案。 I calculate an attenuation factor from the distance from the camera in the vertex shader, and I gradually flatten the waves in the distance.我从顶点着色器中与相机的距离计算了一个衰减因子,并逐渐使远处的波浪变平。

The function:功能:

float CalculateWaveAttenuation(float d, float dmin, float dmax)
{
    // Quadratic curve that is 1 at dmin and 0 at dmax
    // Constant 1 for less than dmin, constant 0 for more than dmax
    if (d > dmax) return 0.f;
    else
    {
        return saturate((1.f / ((dmin-dmax)*(dmin-dmax))) * ((d-dmax) * (d-dmax)));
    }
}

Here are the results:结果如下:

阴影 线框

您应该尝试在片段着色器而不是顶点着色器中实现您的“基本着色”算法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM