简体   繁体   中英

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. 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. 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

"HLSL" - GPU code

Basically, you want everything that is pure graphics to happen on the 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.

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" .

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:

  • 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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