开始着色器开发

发布于 2024-07-05 11:45:27 字数 238 浏览 3 评论 0原文

我想开始使用 Microsoft 的 XNA 进行一些游戏开发。 其中一部分是着色器开发,但我不知道如何开始。 我知道 nVidia 的 FX Composer 是开发着色器的绝佳工具,但我没有找到关于如何实际开始的许多有用且更新的内容。

您会推荐哪些教程?

I want to get started doing some game development using Microsoft's XNA. Part of that is Shader development, but I have no idea how to get started. I know that nVidia's FX Composer is a great tool to develop shaders, but I did not find much useful and updated content on how to actually get started.

What tutorials would you recommend?

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

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

发布评论

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

评论(9

遗心遗梦遗幸福 2024-07-12 11:45:27

在 XNA(显然使用 DirectX)中开发着色器需要了解 HLSL 或着色器组件。 我建议先熟悉前者,然后再深入了解后者。

在编写任何着色器之前,最好对着色器管道有深入的了解,并尝试了解使用可编程着色器时可能发生的情况。 当您熟悉像素的生命周期(从源数据一直到屏幕)时,理解着色器的示例就会变得容易得多。

接下来尝试编写自己的 HLSL,它可以执行固定 T&L 的操作管道用来做,只是为了让你脏手。 这相当于顶点/像素着色器世界中的“hello world”程序。 当您能够做到这一点并且理解了自己所写的内容时,您就准备好继续编写更有趣的内容了。

下一步,您可能需要在其中一个着色器中模拟基本的镜面照明来自单一光源。 然后,您可以沿着轨道调整它以使用多个灯光。 玩转颜色和灯光的移动。 这也将有助于熟悉着色器常量的使用。

当您同时拥有几个基本着色器时,您应该尝试使您的游戏/引擎在不同的对象上使用多个/不同的着色器。 开始添加一些其他位,例如基本的 凹凸法线贴图

当你到达这个阶段时,世界都是你的。 您可以开始深入研究一些时髦的效果,甚至可以考虑使用 GPU 来实现比最初预期更多的用途。

对于那些更高级的人,有几本免费的在线好书,其中包含 Nvidia 的一些重要信息 此处此处

不要忘记有一个名为 ShaderX 的优秀书籍系列,其中涵盖了一些很棒的着色器内容。 有12, 3456 已印刷,7 即将推出。

祝你好运。 如果你让一些着色器运行起来,我很乐意看到它们:)

Development of shaders in XNA (which obviously uses DirectX) requires knowledge of HLSL or shader assembly. I'd recommend getting familiar with the former before diving into the latter.

Before writing any shaders, it's a good idea to get solid understanding of the shader pipeline, and attempt to get your mind around what is possible when using programmable shaders. When you're familiar with the life of a pixel (from source data all the way through to the screen) then understanding examples of shaders becomes a lot easier.

Next make an attempt to write your own HLSL which does what the Fixed T&L pipeline used to do, just to get you hands dirty. This is the equivalent of a "hello world" program in vertex/pixel shader world. When you're able to do that and you understand what you've written you're ready to go onto the more fun stuff.

As a next step you might want to simulate basic sepcular lighting in one of your shaders from a single light source. You can then adapt this down the track to use multiple lights. Play with colours, and movement of lights. This will help get familiar with the use of shader constants as well.

When you have a couple of basic shaders together, you should attempt to make it so that your game/engine uses multiple/different shaders on different objects. Start adding some other bits like basic bump or normal maps.

When you get to this stage, the world is your oyster. You can start diving into some funky effectcs, and even consider using the GPU for more than it was originally intended.

For those who are a little more advanced, there are a couple of good books that are available for free online which have some great information from Nvidia here and here.

Don't forget that there's an excellent series of books called ShaderX which covers some awesome shader stuff. There's 1, 2, 3, 4, 5 and 6 already in print, and 7 is coming soon.

Good luck. If you get some shaders going, I'd love to see them :)

初见 2024-07-12 11:45:27

我只想重申一下《GPU Gems》书籍的伟大之处——对于任何严肃的图形开发来说,这都是真正出色的资源。

OJ 基本上总结了一个非常好的学习过程,我只是补充说,拥有良好的几何数学基础(至少是向量/矩阵)是不可低估的 - 但它并不像人们有时认为的那么难。 了解点积、叉积、法向量和矩阵乘法是什么以及做什么是一个很好的第一步:)。 尝试准确理解世界/视图/投影-剪辑/屏幕空间之间发生了什么,透视划分是什么,等等。

当我开始学习时,一个很好的练习是在软件中实际实现整个 T&L 管道,完成这是一个漫长的过程,可能看起来不值得,因为我确信您只想深入研究有趣的东西,但是正确理解正在发生的事情确实很有用,并且当您总是这样做时,这将证明是值得的遇到更阴险且难以诊断的错误。

最初不要放弃像 FX Composer 这样的工具,它们对于原型设计很有用,但从长远来看,拥有坚实的基础知识更有价值。

I'd just like to reiterate how great the GPU Gems books are - a truly fantastic resource for any serious graphics development.

OJ has basically summed up a really good process of learning, I'd just add that having a good foundation in geometric math (vectors/matrices as a minimum) cannot be underestimated - but it's not as hard as people sometimes make out. Learning what a dot product, cross product, normal vector and matrix multiply are and do is a good first step :). Try to understand exactly what is happening between World/View/Projection-Clip/Screen space, what the perspective divide is, etc.

When I was beginning learning, a good exercise is to actually implement the entire T&L pipeline in software, complete with clipping/culling etc. This is a long process and may not seem worthwhile as I'm sure you want to just dive into the fun stuff, but having a proper understanding of what's going on is really useful and will prove worthwhile when you invariably run into more insidious and difficult to diagnose bugs.

Try not to be sidelined with tools like the FX Composer initially, they're useful for prototyping, but having a solid foundation in the basics is much more worthwhile in the long run.

晨光如昨 2024-07-12 11:45:27

开始使用着色器的最佳方法之一是阅读 Frank Luna 撰写的《使用 DirectX 9.0ca 着色器方法进行 3D 游戏编程简介》。 作者首先介绍了DirectX和HLSL,然后逐步揭示了着色器的强大功能。 他从非常简单的着色器开始,但到本书结束时,您知道如何创建照明、阴影、粒子系统等。很棒的书。

OJ建议您阅读ShaderX系列,但是那里的内容不适合初学者,因此当您迈出第一步时它不会对您有太大帮助。

我还在此处发布了一篇文章 关于帮助您开始游戏开发的最佳书籍。

One of the best ways to get started with shaders is to read Introduction to 3D Game Programming with DirectX 9.0c a Shader Approach by Frank Luna. The author first introduces the DirectX and the HLSL and then gradualy reveals the power of shader. He starts with very simple shaders but by the end of the book you know how to create lighting, shadows, particle systems, etc. Great Book.

OJ suggested that you read the ShaderX series, but the stuff there is not for beginners so it will not help you a lot when you are making your first steps.

I've also posted an article here about the best books that will get you started with game development.

抱猫软卧 2024-07-12 11:45:27

我会加入对 OJ 的赞扬——确实是一个很好的答案。
不过,一旦您有了基本的了解,您就可以通过下载以下两个出色工具之一来快速学习很多知识:

完成此操作后,转到他们的项目库并开始浏览示例,从基本的开始着色和移动到阴影、法线贴图、材质、效果以及您感兴趣的一切。
开始一个项目,根据你设定的一些目标开始改变算法,看看如何实现它。
您会发现许多示例非常先进,它们会开拓您的视野。

玩得开心

I'd join the praises given to OJ - truely a good answer.
Still, once you do have the basic understanding you can learn a lot and fast by downloading one of the following two great tools:

Once you do that, go to their project libraries and start browsing through examples, starting with the basic shading and moving to shadows, normal mapping, materials, effects and everything you find of interest.
take a project, start altering the algorithms according to some goals you set and see how to get it.
You'll find that many of the examples are really advanced and they will open up your horizons.

Have fun

公布 2024-07-12 11:45:27

虽然已经给出了很多好的建议,但如果您很难理解所涉及的步骤,Mental Mill 提供了构建着色器的可视化方式(Artist Edition 免费与 Fx Composer 捆绑在一起 - 本身也是免费的!)。

虽然您最好直接长期学习 HLSL 代码,但 Mental Mill 可以为您生成这些 Fx 文件(以便您可以查看更改)。 请注意,与所有代码生成器一样,它比您了解 HLSL 后可能做的要冗长一些!

从一种方法到另一种方法,效果的视觉进展非常令人印象深刻!

Whilst a lot of good advice has already been given, if you're having a hard job getting your mind around the steps involved, Mental Mill provides a visual way of constructing Shaders (the Artist Edition is bundled free with Fx Composer -- itself also free!).

Whilst you'd be better off long term learning the HLSL code directly, Mental Mill can generate these Fx files for you (so you can peek at the changes). Note, like all code-generators, it's a little more verbose than you're likely to do once you understand HLSL!

The visual progression of the effects, from one method to another, is very impressive!

烟柳画桥 2024-07-12 11:45:27

SAMS 的 Chad Carter 的 XNA Unleashed 是 XNA 的一个很好的起点,并且几乎没有假设在开始之前了解游戏开发实践或硬数学知识。 它有关于基本和高级着色器的两章。

顺便说一句,请留意 Google 上的 WPF Shader 教程,它现在使用相同的技术来允许 WPF 应用程序中的客户着色器,并且我认为教程在很大程度上与 XNA 兼容。

SAMS's XNA Unleashed by Chad Carter is a great starting point for XNA and assumes little knowledge of game development practices or hard maths before you start. It has two chapters on basic and advanced shaders.

As a sidenote, keep an eye out on Google for WPF Shader tutorials, it now uses the same technology to allow customer shaders in WPF applications and tutorials for that I believe are largely compatible with XNA.

深海少女心 2024-07-12 11:45:27

我没有使用过 XNA 或 DirectX。 但是,为了了解使用 Cg 进行着色器编程的基础知识,Cg 教程是我找到的最好的书。

I haven't used XNA or DirectX. But, for getting to know the basics of shader programming with Cg, the Cg Tutorial is the best book I've found.

烧了回忆取暖 2024-07-12 11:45:27

您还应该看看 RenderMonkey。 这是一个很好的工具。 就书籍而言,请查看 Riemer Grootjans 的《XNA 2.0 游戏编程食谱》……很棒的书。

You should also look at RenderMonkey. It's a good tool. As far as books go, check out XNA 2.0 Game Programming Recipes from Riemer Grootjans ... great book.

不一样的天空 2024-07-12 11:45:27

关于视觉着色器编辑器的一个快速思考。
这些类型的编辑器玩起来非常有趣,但我真的非常建议坚持使用基于文本的 HLSL(RM 和 FXC 都可以完成这项工作)。 我是一名游戏开发人员,已经构建了一些着色器系统(例如《战地 2》和《Farcry 2》中的着色器系统),说实话,我发现 HLSL 比迄今为止的任何图形着色器网络都更有价值。

有些事情比如遵循执行流程、调试着色器或能够快速迭代测试用例,可以让您获得通过可视化工具几乎不可能获得的洞察力。

我自己也使用过视觉着色器构建器,我喜欢它们,有一天,当着色不再像今天这样对性能至关重要时,它们可能是完成这项工作的正确工具。

..虽然我的猜测是,在那一天到来之前我们会看到延迟照明,并且可能会看到完整的软件渲染;)

One quick thought on visual shader editors.
Those sort of editors are a very fun thing to play with, but I would really, really recommend to stick with working with text-based HLSL (there both RM and FXC do the job). I work as a game dev and have built a few shader systems (the one in Battlefield 2 and Farcry 2, for instance) and, to be honest, have found that HLSL is more valuable than any graphic shader network to date.

There are things like following the flow of execution, debugging the shader or being able to quickly iterate test cases that give you an insight that is pretty much impossible to get through a visual tool.

I have used visual shader builders myself, and I like them, and one day, when shading is not as performance-critical as it is today, they might be the right tool for the job.

..though my guess is that we'll see deferred lighting and probably full software rendering before that day comes ;)

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