OpenGL:使用着色器通过使用预先计算的颜色图来创建顶点照明?

发布于 2024-10-04 02:25:31 字数 382 浏览 3 评论 0原文

首先,我对着色器能做什么知之甚少,而且我对制作顶点光照非常感兴趣。我正在尝试使用 3d 颜色图,该颜色图将用于计算世界该位置的顶点颜色,并通过使用颜色图中的附近颜色来插值颜色。

我无法使用典型的 OpenGL 光照,因为它可能太慢,而且我需要渲染很多灯光。我将首先在颜色图中“渲染”灯光,然后我可以手动映射使用颜色图中相应颜色绘制的每个顶点。

...或者我可以以某种方式自动化这个过程,这样我就不必自己更改顶点的颜色值,但着色器也许可以为我做到这一点?

问题是......这可能吗?如果可能的话:我需要知道什么才能使它成为可能?

编辑:请注意,我还需要有效地更新光照贴图,而不关心光照贴图的大小,因此应该仅在我想要更新的光照贴图的特定部分进行更新。

First of all, I have very little knowledge of what shaders can do, and i am very interested in making vertex lighting. I am attempting to use a 3d colormap which would be used to calculate the vertex color at that position of the world, and also interpolate the color by using the nearby colors from the colormap.

I cant use typical OpenGL lighting because its probably too slow and theres a lot of lights i need to render. I am going to "render" the lights at the colormap first, and then i could either manually map every vertex drawn with the corresponding color from the colormap.

...Or i could somehow automate this process, so i wouldnt have to change the color values of vertexes myself, but a shader could perhaps do this for me?

Questions is... is this possible, and if it is: what i need to know to make it possible?

Edit: Note that i also need to update the lightmap efficiently, without caring about the size of the lightmap, so the update should be done only at that specific part of the lightmap i want to update.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杀手六號 2024-10-11 02:25:31

听起来您想要做的就是将灯光渲染到颜色图,然后使用颜色图作为纹理,但不是贴花模式,而是将其设置为调制模式,因此它与现有的颜色而不是仅仅替换它。

但这在一方面有所不同:它不仅仅影响顶点,而是映射到各个片段(本质上是像素)。

编辑:我想到的不是 3D 纹理——而是立方体贴图。基本上,创建一个围绕“世界”中所有事物的虚拟立方体。为该立方体的每个面创建一个 2D 纹理。将颜色渲染到立方体贴图。然后,为了给顶点着色,您(实际上)从中心向外延伸一条射线,穿过顶点,到达立方体。您在立方体贴图上点击的像素为您提供了该顶点的照明颜色。

更新应该相对高效——顶部、底部、正面等都有正常的 2D 纹理,并且可以根据需要更新它们。

It almost sounds like what you want to do is render the lights to your color map, then use your color map as a texture, but instead of decal mode set it to modulate mode, so it's multiplied with the existing color instead of just replacing it.

That is different in one way though: instead of just affecting the vertexes, it'll map to the individual fragments (pixels, in essence).

Edit: What I had in mind wasn't a 3D texture -- it was a cube map. Basically, create a virtual cube surrounding everything in your "world". Create a 2D texture for each face of that cube. Render your coloring to the cube map. Then, to color a vertex you (virtually) extend a ray outward from the center, through the vertex, to the cube. The pixel you hit on the cube map gives you the color of lighting for that vertex.

Updating should be relatively efficient -- you have normal 2D textures for the top, bottom, front, etc., and you update them as needed.

ぃ双果 2024-10-11 02:25:31

如果您无法使用固定功能管道功能,则执行每个顶点照明的最佳方法应该是在顶点着色器中对每个顶点进行所有照明计算,然后当您将其传递到片段着色器时,它将在整个片段着色器中正确插值。脸。

使用大量光源时处理性能问题的另一种方法是使用延迟渲染只会对实际可见的几何体进行光照计算。

If you cant use the fixed function pipeline functionality the best way to do per vertex lighting should be to do all the lighting calculations per vertex in the vertex-shader, when you then pass it on the the fragment shader it will be correctly interpolated across the face.

Another way to deal with performances issues when using a lot of light sources is to use deferred rendering as it will only do lighting calculation on the geometry that is actually visible.

つ可否回来 2024-10-11 02:25:31

这是可能的,但在当前硬件上无效。

您想要将光体积渲染为 3D 纹理。光栅化器在 2D 表面上工作,因此您的体积必须沿其中一个轴分割。分割可以通过以下方式之一完成:

  • 每个分割的不同绘制调用
  • 实例化绘制,基于 glInstanceID 进行层选择(将需要几何着色器)
  • 直接从单个绘制调用在几何着色器中分支

为了实现它,我建议阅读 GL-3 规范和示例。这并不容易,对于复杂场景的结果也不会足够快。

That is possible, but will not be effective on the current hardware.

You want to render light volumes into 3d texture. The rasterizer works on a 2D surface, so your volumes have to be split along one of the axises. The split can be done in one of the following ways:

  • Different draw calls for each split
  • Instanced draw, with layer selection based on glInstanceID (will require geometry shader)
  • Branch in geometry shader directly from a single draw call

In order to implement it, I would suggest reading GL-3 specification and examples. It's not going to be easy, nor it will be fast enough in the result for complex scenes.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文