如何编写“材料模块”用于 3D 渲染?

发布于 2024-08-06 21:37:35 字数 229 浏览 2 评论 0原文

在某些时候,我想为我的 3D 渲染引擎编写某种类型的动态材质处理模块。它应该是可移植的(GL、D3D 等)。当我说“动态”时,我指的是能够加载材质定义和数据运行时的模块(通过我的资源管理模块)。

材质模块应该处理基本的图元:纹理、法线贴图、片段着色器等等。

我该如何开始?反复试验肯定会产生两三个完全毫无价值的原型,我宁愿跳过。您能给我指出一些好的、甚至很棒的设计/实现/教程/文章,它们可能对我的探索有帮助吗?

At some point I would like to write some type of dynamic material-handling module for my 3D rendering engine. It should be portable (GL, D3D, etc). And when I say "dynamic" I mean a module that is able to load material definitions and data runtime (through my resource management module).

The material module should cope with basic primitives: textures, normal maps, fragment shaders, and so on and so forth.

How do I start? Trial and error is sure to result in two or three totally worthless prototypes, which I would prefer to skip. Could you point me at some good, or even great, design/implementation/tutorial/article that might help me in my quest?

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

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

发布评论

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

评论(2

烟雨扶苏 2024-08-13 21:37:35

我首先查看免费提供的 Blender 代码。

另外,看看这本书:3d 计算机图形

我发现它非常有帮助在解释基本原理时

I'd start by looking at the freely available Blender code.

Also, have a look at this book: 3d Computer Graphics

I found it enormously helpful at explaining the fundamentals

青衫负雪 2024-08-13 21:37:35

这是一个非常大的话题;构建一个高效的材料系统一开始很难,但加上你希望它是可移植的和动态的,而且它实际上并没有比这更复杂的了。

值得一看的地方(Google 会找到所有这些):

  • 游戏编程宝石书籍
  • 图形编程宝石书籍
  • ShaderX 书籍
  • GameDev-Algorithms 邮件列表是一个极好的资源,SWEng-GameDev 列表也是如此
  • 。例如 Ogre3D 或 Unity。

建议:

  • 看看 D3D10 将状态处理为不可变状态块的方式;这很好,因为它适合 3D 硬件
  • 将材质状态和材质数据视为独立的事物;状态是诸如 alpha 混合类型之类的东西,而数据是诸如漫反射颜色或纹理之类的东西。状态是不可变的,是对渲染通道进行排序的基础,而数据是动态的并且可以根据渲染对象设置/更改
  • 我找不到任何好的着色器解决方案。 GLSL 非常有用,除非您想在 Windows 上支持 Intel 硬件,而 Windows 上没有任何 GL 驱动程序。 HLSL 仅适用于 DirectX。 Cg 对我来说还不够多线程运行。如果您的情况相同,唯一的选择是提供特定的着色器配置文件(例如“HLSL Vertex Shader 3.0”)并让开发人员处理差异,或者以某种方式将其全部抽象出来,这会增加工作量并且可能不太灵活
  • 使其动态化只是正确跟踪引用等问题。困难的部分是不太明显的情况,例如如果您更改渲染网格的材质,则可能需要不同的顶点格式,因此您将拥有更新网格的顶点缓冲区

Thats a really big topic; architecting an efficient material system is hard to begin with, but add in that you want it to be portable AND dynamic, and it doesn't really get much more complex than that.

Places to look (Google will find all these):

  • Game Programming Gems books
  • Graphics Programming Gems books
  • ShaderX books
  • The GameDev-Algorithms mailing list is an excellent resource, also the SWEng-GameDev list
  • Look at what other APIs do; for example Ogre3D or Unity.

Advice:

  • Look at the D3D10 way of handling state as immutable state blocks; this is good because it suits 3D hardware
  • Think of material state and material data as separate things; state is stuff like alpha blending type, while data is things like diffuse color or texture. State is immutable, and the basis for sorting your rendering pass, while data is dynamic and can be set/changed per-rendered object
  • I couldn't find any good solutions for shaders. GLSL is great unless you want to support Intel hardware on Windows, where there aren't any GL drivers. HLSL is DirectX only. Cg couldn't be run multithreaded enough for me. If your situation is the same, the only options are to offer specific shader profiles (eg 'HLSL Vertex Shader 3.0') and let the developer cope with the differences, or abstract it all away somehow, which is more work and may be less flexible
  • Making it dynamic is just a matter of keeping track of references correctly etc. The hard part is the less obvious cases, like if you change a material that a mesh is being rendered with, it might require a different vertex format, so you will have to update the mesh's vertex buffers
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文