简体   繁体   English

使用Direct 3D时,应该在代码中处理什么以及在HLSL中应该处理什么?

[英]When using Direct 3D, what should be processed in code and what should be processed in HLSL?

I am very new to 3D programming, namely with DirectX. 我是3D编程的新手,即使用DirectX。 I have been trying to follow tutorials on how to do basic things, and I have been looking at the samples provided by Microsoft. 我一直在尝试按照如何做基本事情的教程,我一直在看微软提供的示例。 One of the big questions I have had is how to tell what calculations should be done in the actual game code and what calculations should be done in HLSL. 我遇到的一个重大问题是如何判断在实际游戏代码中应该进行哪些计算以及在HLSL中应该进行哪些计算。 I have not been able to understand what should be done where, because it looks like, to me, you could have almost all code pertaining to calculations in your shader file, or you could have it all in the executable code and only send the bear minimum to the pixel and vertex shaders. 我无法理解应该在哪里做什么,因为看起来,对我来说,你几乎可以拥有与着色器文件中的计算相关的所有代码,或者你可以将它全部放在可执行代码中并且只发送熊最小的像素和顶点着色器。 How can one tell what code should go where? 如何判断代码应该放在哪里? If you need an example, I'll try to find one. 如果你需要一个例子,我会试着找一个。

"Code" - CPU code “代码” - CPU代码

"HLSL" - GPU code “HLSL” - GPU代码

Basically, you want everything that is pure graphics to happen on the GPU. 基本上,您希望所有纯图形都在GPU上发生。 That is, when the information about what you want to render has been sent to the GPU, it should take over and use that information to generate the final image. 也就是说,当有关您要渲染的内容的信息已发送到GPU时,它应接管并使用该信息生成最终图像。

You want to the CPU to say to the GPU "this is what I want to render, and here is everything you need to make it happen" and then make sure to tell the GPU "this is how you render it" . 你想让CPU对GPU说“这就是我要呈现的内容,这里就是你需要做的一切” ,然后确保告诉GPU “这就是你渲染它的方式”

Some examples (not a complete or final list in anyway): 一些例子(无论如何都不是完整的或最终的列表):

CPU: 中央处理器:

  • Anything dealing with window opening/closing/resizing 处理窗口打开/关闭/调整大小的任何事情
  • User input from mouse, keyboard 用户从鼠标,键盘输入
  • Reading and setting configuration 读取和设置配置
  • Generating and updating view matrices 生成和更新视图矩阵
  • Application logic 应用逻辑
  • Setting up and initializing rendering (textures, buffers etc) 设置和初始化渲染(纹理,缓冲区等)
  • Generating vertex data (position, texture coordinates etc) 生成顶点数据(位置,纹理坐标等)
  • Creating graphic entities (triangles, textures, colors etc) 创建图形实体(三角形,纹理,颜色等)
  • Handling animation (timestepping, swapping buffers) 处理动画(时间步,交换缓冲区)
  • Sending updated data to the GPU for each frame 将更新的数据发送到每帧的GPU

GPU: GPU:

  • Use the view matrices to put things on the right place on the screen 使用视图矩阵将东西放在屏幕上的正确位置
  • Interpolate from vertex data to fragment data 从顶点数据到片段数据的插值
  • Shading (usually, this is the most complicated part) 着色(通常,这是最复杂的部分)
  • Calculate and write final pixel color 计算并写入最终像素颜色

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM