更逼真的照明

瑙尔·哈达尔(Naor Hadar)

我已经阅读了这个答案,并且已经尝试过:

for (int i = 0; i < mapArray.GetLength(0); i++)
{
    for (int j = 0; j < mapArray.GetLength(1); j++)
    {
        if (mapArray[i, j] == null)
            CurrentLight = 0f;
        else
        {
            mapArray[i, j].Light = CurrentLight;
            CurrentLight += Tiles.Absorb;
        }
    }
}

结果如下: 游戏照明

如您所见,我的问题是照明不真实,如果当前图块是一个块,该函数将穿过各列并以0.05F的光吸收光线;如果不是图块,则它将重置为0(这是全亮度)。

那棵树主要进入我的眼睛,而光线不是那么好..我应该如何改善它?

谢谢。

尼科·谢特勒(Nico Schertler)

The most important phenomenon in this scenario is light scattering. Light scattering takes place in every direction, not only downwards as you modelled it. You can calculate the lighting with a big linear system of equations, but this is potentially slow (see radiosity). Here is an approximative alternative:

The basic idea is that a block distributes its light to all neighbouring blocks. We start with a 1 for unfilled blocks and 0 for filled blocks (note that I use 0 for "no light" and 1 for "full light"; this seems to be more intuitive"). After we have initialized all blocks with their respective values, we can start the following distribution pass (I omitted range checks; that's up to you):

float[, ] incomingLight; // should have the same size as the map 
                         // and saves the additional light for each block
for each i,j in the map
    float myLight = (map[i, j] == null ? 1 : map[i, j].Light)       
    incomingLight[i - 1, j    ] += 0.10f * myLight //Add light to the left neighbour
    incomingLight[i - 1, j - 1] += 0.07f * myLight //top left neighbour
    incomingLight[i    , j - 1] += 0.10f * myLight //top neighbour
    //do the same for all remaining neighbours

    incomingLight[i, j] -= (sumOfWeights) * myLight //preserve overall light intensity
    // ...
next
for each i,j in the map
    if(map[i, j] != null)
        map[i, j].Light = min(1, map[i, j].Light + incomingLight[i, j])
    incomingLight[i, j] = 0
next

Now we have illuminated all blocks that are adjacent to a light block. You might need to adjust the weights for the distribution.

We can repeat this pass to create a more realistic lighting. The more often the pass is executed, the deeper the light will scatter. Note that each pass will brighten up the entire scene because unfilled blocks have basically an infinite light intensity.

Another approach, which should be faster but slightly more imprecise, is to calculate the distance of each block to the nearest unblocked tile and use this as a coefficient for the lighting. There are very efficient algorithms to calculate the distance (see distance transform). Calculating the block distance (Manhattan distance) is quite simple and should suffice in your case:

用无穷大或很大的数字初始化填充块,用0初始化未填充的块。然后执行四遍:

float [,] distances //initialized with 0 or infinity

//from top left corner
for y from 0 to height - 1
    for x from 0 to width - 1
        distances[x, y] = min(distances[x, y], distances[x - 1, y] + 1, distances[x, y - 1] + 1)

//from top right corner
for y from 0 to height - 1
    for x width - 1 to 0
        distances[x, y] = min(distances[x, y], distances[x + 1, y] + 1, distances[x, y - 1] + 1)

//from bottom left corner
for y from height - 1 to 0
    for x 0 to width - 1
        distances[x, y] = min(distances[x, y], distances[x - 1, y] + 1, distances[x, y + 1] + 1)

//from bottom rightcorner
for y from height - 1 to 0
    for x width - 1 to 0
        distances[x, y] = min(distances[x, y], distances[x + 1, y] + 1, distances[x, y + 1] + 1)

在那四次通过之后,您具有到distances数组中最近的空闲块的块距

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

更逼真的透视算法

来自分类Dev

javascript中逼真的鼠标移动坐标?

来自分类Dev

如何使用Threejs实现逼真的反射

来自分类Dev

Unity 中逼真的阀轮旋转

来自分类Dev

平滑Java中随机生成的地形以获得逼真的效果

来自分类Dev

如何制作逼真的轮盘赌球旋转动画

来自分类Dev

用逼真的重力使物体跳一次

来自分类Dev

使用SVG制作逼真的(正弦)标记动画/抖动

来自分类Dev

如何制作逼真的轮盘赌球旋转动画

来自分类Dev

平滑Java中随机生成的地形以获得逼真的效果

来自分类Dev

Matlab:逼真的动画弹跳球(模拟地球条件)

来自分类Dev

如何在 CSS/SVG 中创建逼真的光泽效果?

来自分类Dev

使情节提要板视图更逼真

来自分类Dev

如何使用Pure CSS3绘制逼真的平滑缝阴影?

来自分类Dev

具有不同球质量的逼真的球碰撞-小球阻止大球

来自分类Dev

就尺寸和质量而言,是否可以进行逼真的n体太阳系仿真?

来自分类Dev

Unity 3D逼真的加速度计控制

来自分类Dev

具有不同球质量的逼真的球碰撞-小球阻止大球

来自分类Dev

根据随机下限/上限在SQL中生成逼真的数字序列

来自分类Dev

如何组合多个连续图像来模拟逼真的运动模糊?

来自分类Dev

如何修改简单的汇编代码以使其更逼真?

来自分类Dev

向高斯分布中添加逼真的噪声,同时使样本数量在阈值之上/之下大致保持恒定

来自分类Dev

在哪里可以获得用于设计逼真的静态模型的iOS UI元素模板(图形)?

来自分类Dev

Three.js:如何将映射添加到OBJ对象以获得逼真的金属材质?

来自分类Dev

屏幕键盘真的更安全吗?

来自分类Dev

使移动更加逼真

来自分类Dev

QR码真的更容易被计算机读取吗

来自分类Dev

照明均衡

来自分类Dev

如何在 A-Frame 中渲染逼真

Related 相关文章

  1. 1

    更逼真的透视算法

  2. 2

    javascript中逼真的鼠标移动坐标?

  3. 3

    如何使用Threejs实现逼真的反射

  4. 4

    Unity 中逼真的阀轮旋转

  5. 5

    平滑Java中随机生成的地形以获得逼真的效果

  6. 6

    如何制作逼真的轮盘赌球旋转动画

  7. 7

    用逼真的重力使物体跳一次

  8. 8

    使用SVG制作逼真的(正弦)标记动画/抖动

  9. 9

    如何制作逼真的轮盘赌球旋转动画

  10. 10

    平滑Java中随机生成的地形以获得逼真的效果

  11. 11

    Matlab:逼真的动画弹跳球(模拟地球条件)

  12. 12

    如何在 CSS/SVG 中创建逼真的光泽效果?

  13. 13

    使情节提要板视图更逼真

  14. 14

    如何使用Pure CSS3绘制逼真的平滑缝阴影?

  15. 15

    具有不同球质量的逼真的球碰撞-小球阻止大球

  16. 16

    就尺寸和质量而言,是否可以进行逼真的n体太阳系仿真?

  17. 17

    Unity 3D逼真的加速度计控制

  18. 18

    具有不同球质量的逼真的球碰撞-小球阻止大球

  19. 19

    根据随机下限/上限在SQL中生成逼真的数字序列

  20. 20

    如何组合多个连续图像来模拟逼真的运动模糊?

  21. 21

    如何修改简单的汇编代码以使其更逼真?

  22. 22

    向高斯分布中添加逼真的噪声,同时使样本数量在阈值之上/之下大致保持恒定

  23. 23

    在哪里可以获得用于设计逼真的静态模型的iOS UI元素模板(图形)?

  24. 24

    Three.js:如何将映射添加到OBJ对象以获得逼真的金属材质?

  25. 25

    屏幕键盘真的更安全吗?

  26. 26

    使移动更加逼真

  27. 27

    QR码真的更容易被计算机读取吗

  28. 28

    照明均衡

  29. 29

    如何在 A-Frame 中渲染逼真

热门标签

归档