GLSL 代码到具有高度图渲染的 2D 地形
我有一个基于二维图块的地图和高度图图像,我想用它来使地图看起来不那么平坦。但我对 SFML 中使用的 GLSL 很陌生。我正在寻找一些 GLSL 着色器,我可以将平铺纹理和部分高度图传递到相同的坐标或创建高度错觉的东西。但是我自己做所有事情,我没有时间仅仅为了我想使用的这个着色器来学习 GLSL,所以感谢您的任何回复(最好是如果有人可以发布一些着色器代码并向傻瓜解释它是怎样的)在 .cpp 文件中使用)
I have a 2d tile based map and image of height map, which I would like to use to make map look less flat. But I am new to GLSL which is used in SFML. I am looking for some GLSL shader to which I can pass tile texture and part of height map on the same coordinates or something to create height illusion. But I am doing everything by myself and I dont have time to learn GLSL just for this one shader I would like to use, so thanks for any reply (best would be if someone could post some shader code and explaint it for dummies how is it used in .cpp file)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可能对“视差遮挡贴图”技术感兴趣。可以在此处找到一个好的实现。
You are probably interested in the technique "Parallax Occlusion Mapping". A good implementation can be found here.
这会将 Z 踢到屏幕上,从而产生高度图的错觉。
它实际上并没有改变几何形状。
[编辑] 这对于自上而下的视图没有用。我会尝试添加某种基于新 Z 和光线方向的阴影效果。
此行:pos.z += color.x + color.y + color.z; 是推动 Z 的内容。您可以为比例指定正数或负数。
这是非常简单的片段程序..
This will kick the Z on the screen to give the illusion of a height map.
It does not actually change the geometry.
[edit] This is not useful for top down view.. Id try adding some sort of shadow effect based on the new Z and a light direction.
This line: pos.z += color.x + color.y + color.z; is what pushes the Z. You can give scale a positive or negative number.
And here is the VERY simple Fragment program..
这会使地形网格体变形,无论光线在世界空间中的位置,其基础都是气泡/圆顶形状。地形细分得越多,结果就越好。
This deforms the a terrain mesh with a bubble/dome shape base where ever the light is in world space. The more the terrain is tessellated the better the results.