Make the most of the programmable GPU in the game

Source: Internet
Author: User

Before the beginning of the article, I would like to take this garden to sincerely apologize to my dearest Mi bao, I remember my serious mistakes, as a training, all my friends testify, I will be self-restraint, repent. I'm fully aware of the GPU's massive throughput and strong floating-point computing capabilities, will be very high to improve the program performance, but also to give full play to the value of the graphics card, GPU as a computer 2 programmable high-performance chip, has long been not a common programmer due attention, mainly because of its programming trouble, lack of data tools. Here I will describe my game programming as much as possible using the GPU to do some of the experience, mainly to express a reasonable use of computer resources of a thought bar.

I am not familiar with DX10 and SM3.0, so more useful GS data output, and even more powerful cuda are not within the scope of this article, here more discussion SM2.0 and DX9, believe that most of the friends should have the conditions of practice. Professional GPGPU are using scientific calculation as an example, I think it is not good, or simple, here I say how to put all the board's geometry calculations on the GPU.

Bulletin boards are familiar to graphic programmers, is to let the geometry (usually quadrilateral) always face the camera, is actually a rotating process, the simplest is snowflakes, bushes and so on, here I want to tell a slightly more complicated example, such as Warcraft in the chain of magic, or the sky in the Fractal Lightning, In fact, these are links between 2 points of one or more pieces of the geometry, a section may be a quadrilateral, or multiple quadrilateral, as shown below:

If a paragraph is not a piece of the rotation, so we mainly say that the above situation. Mage to one or more targets to send a link to the magic, in fact, is in the target to generate links between the surface slices, and on the surface of the relevant texture animation, when the direction between the target constantly changing the geometric transformation and other operations. The principle is very simple, that is, so that all the patches can face the audience, so that in a specific direction to watch the performance of serious distortion, we mainly see how to put all the calculations into the GPU.

First we have to generate all the vertices needed in the CPU, because a GPU without a GS cannot generate vertices. For example, to generate a geometric strip from point A to point B, we generate 8 intermediate points, a total of 10 points. By adjacent 2 points, we can find the middle point of 2 points, pmid= (Pi + Pi+1)/2, we generate 4 vertices for the first segment, and subsequent segments because we share the last 2 vertices of the previous segment, So each paragraph in the back takes only 2 vertices, the geometric coordinates of each vertex are set to the middle point of this segment, pmid, so that the vertices of each segment are in a nest, we need to extend it to a quadrilateral in VS, but we need information about how the current vertex expands, as shown in the following figure:

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.