Shader Programming Study Notes (iii)--three major mainstream programming languages HLSL/GLSL/CG

Source: Internet
Author: User
Tags pixel coloring

Three major mainstream programming languages HLSL/GLSL/CG

Shader Language

The development direction of Shader language is to design a high-level language that can be compared with C + +, Java and so on, "give programmers a flexible and convenient way of programming", and "control the rendering process as much as possible" while "taking advantage of the parallelism of graphics hardware to raise the efficiency of Algorithms ".
Shader Language currently has 3 languages: OpenGL-based OpenGL Shading Language, abbreviated GLSL, and high-level shading Language based on DirectX, or HLSL; There are also Nvidia's C for Graphic, or CG language.

About OpenGL

OpenGL (Full-write open graphics Library) is a professional graphics program interface that defines cross-programming language and cross-platform programming interface specifications. It is used for three-dimensional image (two-dimensional also), is a powerful, easy to call the bottom-level graphics library. OpenGL is the most widely accepted 2D/3D graphics API in the industry, and since its inception, it has spawned thousands of of outstanding applications on a variety of computer platforms and devices. It is independent of the Windows operating system or other operating systems, and is also network-transparent. In industries including CAD, content authoring, energy, entertainment, game development, manufacturing, and virtual reality. OpenGL is a hardware-agnostic software interface that can be ported between different platforms such as Windows 95, Windows NT, Unix, Linux, MacOS, and OS/2. As a result, OpenGL-enabled software is well-ported and can be used for a wide range of applications.

OpenGL development has been in a relatively slow situation, each version of the increase in the number of new technology is very few, mostly just some of the changes and improvements. In July 1992, SGI released the 1.0 version of OpenGL, which was followed by the development of the Windows NT version of OpenGL with Microsoft, so that some large 3D graphics processing software that had to run on top of the high-end graphics workstations could be used on a microcomputer. The 1995 OpenGL 1.1 release, which has a lot more performance than 1.0, has added some new features, including improved printer support, inclusion of OpenGL calls in enhanced meta-files, new features of vertex arrays, improved vertex position, normals, colors, color indices, texture coordinates, Polygon Edge identification of the transfer speed, introduced a new texture characteristics and so on. OpenGL 1.5 also adds "OpenGL Shading Language", which is the bottom core of OpenGL 2.0 for the extended functionality of shading objects, vertex shading, and fragment coloring techniques.

About DirectX

DirectX (Direct eXtension, abbreviated DX) is a multimedia programming interface created by Microsoft Corporation. Implemented by the C + + programming language, followed by COM. is widely available for Microsoft Windows, Microsoft Xbox, Microsoft Xbox 360, and Microsoft Xbox One video game development, and can only support these platforms. The latest version of DIREXTX 12, created in the latest Windows 10. DirectX is a set of technologies that are designed to make Windows-based computers an ideal platform for running and displaying applications that have rich multimedia elements such as panchromatic graphics, video, 3D animations, and rich audio. DirectX includes security and performance updates, as well as many new features that cover all technologies. Applications can access these new features by using the DirectX API.

DirectX strengthens 3D graphics sound effects, and provides designers with a common hardware driver standard, so that game developers do not have to write different drivers for each brand of hardware, but also reduce the user installation and set the complexity of hardware. In the literal sense, direct is directly meaning, and the latter side of the x represents a lot of meaning, from this point you can see that the advent of DirectX is for many software to provide direct service.

For example, in the past in DOS players play games, not installed on the play, they often first to set the brand and model of the sound card, and then set the IRQ (interrupt), I/O (input and output), DMA (access mode), if the setting is not correct, then the game sound will not be sent out. This part of the Setup not only makes the player hurt their brains, the game developers are more headache, in order to allow the game to run correctly, developers must at the beginning of the game, the market all the sound card hardware data collected, and then according to different APIs (application programming Interface) to write different drivers. This is difficult for game-maker companies, so there are few multimedia games at the time. Microsoft has seen this issue, for the public manufacturers to launch a common application interface--directx. As long as the game is developed in accordance with DirectX, regardless of the graphics card, sound card model, all can play, but also to play the best results. Of course, if you use a graphics card, the driver for the sound card must support DirectX.

Cg

GLSL and HLSL are based on both OpenGL and Direct3D interfaces, and the two cannot be mixed, in fact OpenGL and Direct3D have always been enemies, long battles. OpenGL has built up a huge user base in its long-term development, and these users will choose GLSL to learn. GLSL inherited the good portability of OpenGL, once on the UNIX and other operating systems alone lead. But GLSL's grammatical system is playing independently. Microsoft's poor HLSL portability is a big part of the Windows platform, which limits the way HLSL is promoted and developed. But the HLSL used in the DX game field is deeply rooted.
CG Language (C for Graphic) is a high-level shading language designed for GPU programming, CG strongly retains most of the semantics of C and frees developers from hardware details, while CG also has other benefits of a high-level language, such as easy reusability of code, improved readability, and compiler code optimization. CG is a graphics processor programming language that can be widely supported by OpenGL and Direct3D. CG language and OpenGL, Direct3D are not the same level of language, but the upper layer of OpenGL and DirectX, that is, the CG program is running on the basis of OpenGL and DirectX standard vertex and pixel coloring. CG is co-working with Nvidia and Microsoft to develop a consistent syntax and semantics for standard hardware lighting languages. So, HLSL and CG are actually the same languages.

Summarize

In the official Unity Manual, the shader program embeds small fragments written in CG/HLSL, starting with "Cgprogram" and ending with "cgend". So, the unity official is mainly uses the CG/HLSL to write the shader program fragment. The Unity official manual also shows that GLSL can be used to extend the CG/HLSL program, but unity officials recommend writing and testing using native GLSL. If you don't use native GLSL, you need to know that your platform must be a mobile device or Linux with Mac OS X, OpenGL ES 2.0 or more. In general, Unity will cross-compile CG/HLSL into optimized GLSL. So we have a variety of options, and we can either consider using CG/HLSL or using GLSL. However, because CG/HLSL is better cross-platform, it prefers to write shader programs using CG/HLSL.

Shader Programming Study Notes (iii)--three major mainstream programming languages HLSL/GLSL/CG

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.