Shader

An example of two kinds of shadings: Flat shading on the left and Phong shading on the right. Phong shading is an improvement on Gouraud shading, and was one of the first computer shading models developed after the basic flat shader, greatly enhancing the appearance of curved surfaces in renders. Shaders are most commonly used to produce lit and shadowed areas in the rendering of 3D models.
Another use of shaders is for special effects, even on 2D images, (e.g., a photo from a webcam). The unaltered, unshaded image is on the left, and the same image has a shader applied on the right. This shader works by replacing all light areas of the image with white, and all dark areas with a brightly colored texture.

In computer graphics, a shader is a computer program that calculates the appropriate levels of light, darkness, and color during the rendering of a 3D scene—a process known as shading. Shaders have evolved to perform a variety of specialized functions in computer graphics special effects and video post-processing, as well as general-purpose computing on graphics processing units.

Traditional shaders calculate rendering effects on graphics hardware with a high degree of flexibility. Most shaders are coded for (and run on) a graphics processing unit (GPU),[1] though this is not a strict requirement. Shading languages are used to program the GPU's rendering pipeline, which has mostly superseded the fixed-function pipeline of the past that only allowed for common geometry transforming and pixel-shading functions; with shaders, customized effects can be used. The position and color (hue, saturation, brightness, and contrast) of all pixels, vertices, and/or textures used to construct a final rendered image can be altered using algorithms defined in a shader, and can be modified by external variables or textures introduced by the computer program calling the shader.[citation needed]

Shaders are used widely in cinema post-processing, computer-generated imagery, and video games to produce a range of effects. Beyond simple lighting models, more complex uses of shaders include: altering the hue, saturation, brightness (HSL/HSV) or contrast of an image; producing blur, light bloom, volumetric lighting, normal mapping (for depth effects), bokeh, cel shading, posterization, bump mapping, distortion, chroma keying (for so-called "bluescreen/greenscreen" effects), edge and motion detection, as well as psychedelic effects such as those seen in the demoscene.[clarification needed]

History

This use of the term "shader" was introduced to the public by Pixar with version 3.0 of their RenderMan Interface Specification, originally published in May 1988.[2]

As graphics processing units evolved, major graphics software libraries such as OpenGL and Direct3D began to support shaders. The first shader-capable GPUs only supported pixel shading, but vertex shaders were quickly introduced once developers realized the power of shaders. The first video card with a programmable pixel shader was the Nvidia GeForce 3 (NV20), released in 2001.[3] Geometry shaders were introduced with Direct3D 10 and OpenGL 3.2. Eventually, graphics hardware evolved toward a unified shader model.

Design

Shaders are simple programs that describe the traits of either a vertex or a pixel. Vertex shaders describe the attributes (position, texture coordinates, colors, etc.) of a vertex, while pixel shaders describe the traits (color, z-depth and alpha value) of a pixel. A vertex shader is called for each vertex in a primitive (possibly after tessellation); thus one vertex in, one (updated) vertex out. Each vertex is then rendered as a series of pixels onto a surface (block of memory) that will eventually be sent to the screen.

Shaders replace a section of the graphics hardware typically called the Fixed Function Pipeline (FFP), so-called because it performs lighting and texture mapping in a hard-coded manner. Shaders provide a programmable alternative to this hard-coded approach.[4]

The basic graphics pipeline is as follows:

  • The CPU sends instructions (compiled shading language programs) and geometry data to the graphics processing unit, located on the graphics card.
  • Within the vertex shader, the geometry is transformed.
  • If a geometry shader is in the graphics processing unit and active, some changes of the geometries in the scene are performed.
  • If a tessellation shader is in the graphics processing unit and active, the geometries in the scene can be subdivided.
  • The calculated geometry is triangulated (subdivided into triangles).
  • Triangles are broken down into fragment quads (one fragment quad is a 2 × 2 fragment primitive).
  • Fragment quads are modified according to the fragment shader.
  • The depth test is performed; fragments that pass will get written to the screen and might get blended into the frame buffer.

The graphic pipeline uses these steps in order to transform three-dimensional (or two-dimensional) data into useful two-dimensional data for displaying. In general, this is a large pixel matrix or "frame buffer".

Types

There are three types of shaders in common use (pixel, vertex, and geometry shaders), with several more recently added. While older graphics cards utilize separate processing units for each shader type, newer cards feature unified shaders which are capable of executing any type of shader. This allows graphics cards to make more efficient use of processing power.

2D shaders

2D shaders act on digital images, also called textures in the field of computer graphics. They modify attributes of pixels. 2D shaders may take part in rendering 3D geometry. Currently the only type of 2D shader is a pixel shader.

Pixel shaders

Pixel shaders, also known as fragment shaders, compute color and other attributes of each "fragment": a unit of rendering work affecting at most a single output pixel. The simplest kinds of pixel shaders output one screen pixel as a color value; more complex shaders with multiple inputs/outputs are also possible.[5] Pixel shaders range from simply always outputting the same color, to applying a lighting value, to doing bump mapping, shadows, specular highlights, translucency and other phenomena. They can alter the depth of the fragment (for Z-buffering), or output more than one color if multiple render targets are active. In 3D graphics, a pixel shader alone cannot produce some kinds of complex effects because it operates only on a single fragment, without knowledge of a scene's geometry (i.e. vertex data). However, pixel shaders do have knowledge of the screen coordinate being drawn, and can sample the screen and nearby pixels if the contents of the entire screen are passed as a texture to the shader. This technique can enable a wide variety of two-dimensional postprocessing effects such as blur, or edge detection/enhancement for cartoon/cel shaders. Pixel shaders may also be applied in intermediate stages to any two-dimensional images—sprites or textures—in the pipeline, whereas vertex shaders always require a 3D scene. For instance, a pixel shader is the only kind of shader that can act as a postprocessor or filter for a video stream after it has been rasterized.

3D shaders

3D shaders act on 3D models or other geometry but may also access the colors and textures used to draw the model or mesh. Vertex shaders are the oldest type of 3D shader, generally making modifications on a per-vertex basis. Newer geometry shaders can generate new vertices from within the shader. Tessellation shaders are the newest 3D shaders; they act on batches of vertices all at once to add detail—such as subdividing a model into smaller groups of triangles or other primitives at runtime, to improve things like curves and bumps, or change other attributes.

Vertex shaders

Vertex shaders are the most established and common kind of 3D shader and are run once for each vertex given to the graphics processor. The purpose is to transform each vertex's 3D position in virtual space to the 2D coordinate at which it appears on the screen (as well as a depth value for the Z-buffer).[6] Vertex shaders can manipulate properties such as position, color and texture coordinates, but cannot create new vertices. The output of the vertex shader goes to the next stage in the pipeline, which is either a geometry shader if present, or the rasterizer. Vertex shaders can enable powerful control over the details of position, movement, lighting, and color in any scene involving 3D models.

Geometry shaders

Geometry shaders were introduced in Direct3D 10 and OpenGL 3.2; formerly available in OpenGL 2.0+ with the use of extensions.[7] This type of shader can generate new graphics primitives, such as points, lines, and triangles, from those primitives that were sent to the beginning of the graphics pipeline.[8]

Geometry shader programs are executed after vertex shaders. They take as input a whole primitive, possibly with adjacency information. For example, when operating on triangles, the three vertices are the geometry shader's input. The shader can then emit zero or more primitives, which are rasterized and their fragments ultimately passed to a pixel shader.

Typical uses of a geometry shader include point sprite generation, geometry tessellation, shadow volume extrusion, and single pass rendering to a cube map. A typical real-world example of the benefits of geometry shaders would be automatic mesh complexity modification. A series of line strips representing control points for a curve are passed to the geometry shader and depending on the complexity required the shader can automatically generate extra lines each of which provides a better approximation of a curve.

Tessellation shaders

As of OpenGL 4.0 and Direct3D 11, a new shader class called a tessellation shader has been added. It adds two new shader stages to the traditional model: tessellation control shaders (also known as hull shaders) and tessellation evaluation shaders (also known as Domain Shaders), which together allow for simpler meshes to be subdivided into finer meshes at run-time according to a mathematical function. The function can be related to a variety of variables, most notably the distance from the viewing camera to allow active level-of-detail scaling. This allows objects close to the camera to have fine detail, while further away ones can have more coarse meshes, yet seem comparable in quality. It also can drastically reduce required mesh bandwidth by allowing meshes to be refined once inside the shader units instead of downsampling very complex ones from memory. Some algorithms can upsample any arbitrary mesh, while others allow for "hinting" in meshes to dictate the most characteristic vertices and edges.

Primitive and Mesh shaders

Circa 2017, the AMD Vega microarchitecture added support for a new shader stage—primitive shaders—somewhat akin to compute shaders with access to the data necessary to process geometry.[9][10]

Nvidia introduced mesh and task shaders with its Turing microarchitecture in 2018 which are also modelled after compute shaders.[11][12] Nvidia Turing is the world's first GPU microarchitecture that supports mesh shading through DirectX 12 Ultimate API, several months before Ampere RTX 30 series was released.[13]

In 2020, AMD and Nvidia released RDNA 2 and Ampere microarchitectures which both support mesh shading through DirectX 12 Ultimate.[14] These mesh shaders allow the GPU to handle more complex algorithms, offloading more work from the CPU to the GPU, and in algorithm intense rendering, increasing the frame rate of or number of triangles in a scene by an order of magnitude.[15] Intel announced that Intel Arc Alchemist GPUs shipping in Q1 2022 will support mesh shaders.[16]

Unified shaders

Unified shader is the combination of 2D shader and 3D shader.

Compute shaders

Compute shaders are not limited to graphics applications, but use the same execution resources for GPGPU. They may be used in graphics pipelines e.g. for additional stages in animation or lighting algorithms (e.g. tiled forward rendering). Some rendering APIs allow compute shaders to easily share data resources with the graphics pipeline.

Ray tracing shaders

Ray tracing shaders are supported by Microsoft via DirectX Raytracing, by Khronos Group via Vulkan, GLSL, and SPIR-V,[17] by Apple via Metal. On the real hardware implementations, one ray tracing core contains many ray tracing shaders (ray tracing ALUs).

Tensor shaders

Tensor shaders may be integrated in NPUs or GPUs. Tensor shaders are supported by Microsoft via DirectML, by Khronos Group via OpenVX, by Apple via Core ML, by Google via TensorFlow, by Linux Foundation via ONNX.[18] On the real hardware implementations, one tensor core contains many tensor shaders (tensor ALUs).

Parallel processing

Shaders are written to apply transformations to a large set of elements at a time, for example, to each pixel in an area of the screen, or for every vertex of a model. This is well suited to parallel processing, and most modern GPUs have multiple shader pipelines to facilitate this, vastly improving computation throughput.

A programming model with shaders is similar to a higher order function for rendering, taking the shaders as arguments, and providing a specific dataflow between intermediate results, enabling both data parallelism (across pixels, vertices etc.) and pipeline parallelism (between stages). (see also map reduce).

Programming

The language in which shaders are programmed depends on the target environment. The official OpenGL and OpenGL ES shading language is OpenGL Shading Language, also known as GLSL, and the official Direct3D shading language is High Level Shader Language, also known as HLSL. Cg, a third-party shading language which outputs both OpenGL and Direct3D shaders, was developed by Nvidia; however since 2012 it has been deprecated. Apple released its own shading language called Metal Shading Language as part of the Metal framework.

GUI shader editors

Modern video game development platforms such as Unity, Unreal Engine and Godot increasingly include node-based editors that can create shaders without the need for actual code; the user is instead presented with a directed graph of connected nodes that allow users to direct various textures, maps, and mathematical functions into output values like the diffuse color, the specular color and intensity, roughness/metalness, height, normal, and so on. Automatic compilation then turns the graph into an actual, compiled shader.

See also

References

  1. ^ "LearnOpenGL - Shaders". learnopengl.com. Retrieved November 12, 2019.
  2. ^ "The RenderMan Interface Specification".
  3. ^ Lillypublished, Paul (May 19, 2009). "From Voodoo to GeForce: The Awesome History of 3D Graphics". PC Gamer – via www.pcgamer.com.
  4. ^ "ShaderWorks' update - DirectX Blog". August 13, 2003.
  5. ^ "GLSL Tutorial – Fragment Shader". June 9, 2011.
  6. ^ "GLSL Tutorial – Vertex Shader". June 9, 2011.
  7. ^ Geometry Shader - OpenGL. Retrieved on December 21, 2011.
  8. ^ "Pipeline Stages (Direct3D 10) (Windows)". msdn.microsoft.com. January 6, 2021.
  9. ^ "Radeon RX Vega Revealed: AMD promises 4K gaming performance for $499 - Trusted Reviews". July 31, 2017.
  10. ^ "The curtain comes up on AMD's Vega architecture". January 5, 2017.
  11. ^ "NVIDIA Turing Architecture In-Depth". September 14, 2018.
  12. ^ "Introduction to Turing Mesh Shaders". September 17, 2018.
  13. ^ "DirectX 12 Ultimate Game Ready Driver Released; Also Includes Support for 9 New G-SYNC Compatible Gaming Monitors".
  14. ^ "Announcing DirectX 12 Ultimate". DirectX Developer Blog. March 19, 2020. Retrieved May 25, 2021.
  15. ^ "Realistic Lighting in Justice with Mesh Shading". NVIDIA Developer Blog. May 21, 2021. Retrieved May 25, 2021.
  16. ^ Smith, Ryan. "Intel Architecture Day 2021: A Sneak Peek At The Xe-HPG GPU Architecture". www.anandtech.com.
  17. ^ "Vulkan Ray Tracing Final Specification Release". Blog. Khronos Group. November 23, 2020. Retrieved 2021-02-22.
  18. ^ "NNAPI Migration Guide | Android NDK". Android Developers. Retrieved August 1, 2024.

Further reading

Read other articles:

For other uses, see Rehoboth (disambiguation). Town in Massachusetts, United StatesRehoboth, MassachusettsTownGoff Memorial Hall SealLocation in Bristol County in MassachusettsCoordinates: 41°50′25″N 71°15′00″W / 41.84028°N 71.25000°W / 41.84028; -71.25000CountryUnited StatesStateMassachusettsCountyBristolSettled1643Incorporated1645Government • TypeOpen town meetingArea • Total46.8 sq mi (121.1 km2) • Land4...

 

American engineer and entrepreneur, also the first space tourist (born 1940) Dennis TitoBorn (1940-08-08) August 8, 1940 (age 83)Queens, New York City, U.S.NationalityAmericanAlma materNew York University (B.S.)Rensselaer Polytechnic Institute (M.S.)OccupationEntrepreneurSpace careerSpace touristTime in space7d 22h 04m[1]Selection2000[1]MissionsISS EP-1 (Soyuz TM-32 / Soyuz TM-31)Mission insignia Dennis Anthony Tito (born August 8, 1940) is an American engineer and e...

 

B

  此條目介紹的是拉丁字母中的第2个字母。关于其他用法,请见「B (消歧义)」。   提示:此条目页的主题不是希腊字母Β、西里尔字母В、Б、Ъ、Ь或德语字母ẞ、ß。 BB b(见下)用法書寫系統拉丁字母英文字母ISO基本拉丁字母(英语:ISO basic Latin alphabet)类型全音素文字相关所属語言拉丁语读音方法 [b][p][ɓ](适应变体)Unicode编码U+0042, U+0062字母顺位2数值 2歷史發...

Konsili Konstantinopel IIIMiniatur Konsili Oikumenis Ke-6 yang berasal dari abad 14Waktu680–681Diakui oleh Gereja Katolik Roma Gereja Ortodoks Timur Persekutuan Anglikan Gereja Katolik Lama Beberapa gereja Protestan Konsili sebelumnyaKonsili Konstantinopel IIKonsili berikutnyaKonsili Nicea IIPenyelenggaraKaisar Konstantinus IVPemimpinPatriark Georgius I dari KonstantinopelJumlah pesertaKemungkinan 300 orang; penandatanganan dokumen berkisar antara 43 (sesi pertama) hingga 174 (sesi ked...

 

Part of a series on the History of Germany Topics Chronology Historiography Military history Economic history Healthcare Islam LGBT history Jewish history Women's history Territorial evolution Historic states (Holy Roman Empire) Monarchs (Queens, Empresses, 1918, Family tree, Austria, Bavaria, Prussia, Saxony, Württemberg, Mediatised) Early history Germanic peoples Migration Period Barbarian kingdoms Frankish Empire Middle Ages East Francia Kingdom of Germany Holy Roman Empire Eastward sett...

 

马来西亚—英国关系 马来西亚 英国 代表機構马来西亚驻英国高级专员公署(英语:High Commission of Malaysia, London)英国驻马来西亚高级专员公署(英语:British High Commission, Kuala Lumpur)代表高级专员 阿末拉席迪高级专员 查尔斯·海伊(英语:Charles Hay (diplomat)) 马来西亚—英国关系(英語:Malaysia–United Kingdom relations;馬來語:Hubungan Malaysia–United Kingdom)是指马来西亚与英国�...

American academic (1859–1925) For the school in Greensboro, North Carolina, see James B. Dudley High School. Dr.James Benson DudleyBornJames Benson Dudley(1859-11-02)November 2, 1859Wilmington, New Hanover County, North CarolinaDiedApril 4, 1925(1925-04-04) (aged 65)Greensboro, Guilford County, North CarolinaNationalityAmericanOccupationProfessorKnown for2nd President of North Carolina Agricultural and Technical State University 1896–1925[1][2][3][4&#...

 

علاقة ودية بين اب وابنته العلاقات بين الأشخاص هي العلاقات بين شخصين أو أكثر تبدأ من علاقة عابرة[محل شك] وحتى العلاقات الدائمة. وقد تبنى هذه العلاقة على الاستدلال أو الحب أو التضامن الاجتماعي أو تفاعلات العمل المعتادة أو أي أنواع أخرى من العلاقات الاجتماعية. وتتشكل العل...

 

American politician and lawyer (born 1957) This article is about the former Florida politician. For the White House Chief of Staff, see Ron Klain. For others with similar names, see Ron Klein (disambiguation). Ron KleinMember of the U.S. House of Representativesfrom Florida's 22nd districtIn officeJanuary 3, 2007 – January 3, 2011Preceded byClay ShawSucceeded byAllen WestMinority Leader of the Florida SenateIn office2002–2004Preceded byTom RossinSucceeded byLes Miller...

A pentagon is a five-sided polygon. A regular pentagon has 5 equal edges and 5 equal angles. In geometry, a polygon is traditionally a plane figure that is bounded by a finite chain of straight line segments closing in a loop to form a closed chain. These segments are called its edges or sides, and the points where two of the edges meet are the polygon's vertices (singular: vertex) or corners. The word polygon comes from Late Latin polygōnum (a noun), from Greek πολύγωνον (polygōn...

 

Former railway station in England For the Wantage Tramway station, see Wantage railway station. Wantage RoadWantage Road station just prior to closure showing preserved Wantage Tramway loco Shannon.General informationLocationGrove, District of Vale of White HorseEnglandGrid referenceSU414913Platforms2Other informationStatusDisusedHistoryOriginal companyGreat Western RailwayPre-groupingGWRPost-groupingGWR Western Region of British RailwaysKey dates1846Opened7 December 1964Closed for passengers...

 

Kon-Katedral RochesterKon-katedral Santo Yohanes PenginjilCo-Cathedral of St. John the EvangelistKon-Katedral Rochester44°01′23″N 92°28′07″W / 44.0230°N 92.4685°W / 44.0230; -92.4685Lokasi11 4th Ave. SWRochester, MinnesotaNegaraAmerika SerikatDenominasiGereja Katolik RomaSitus webwww.sj.orgSejarahTanggal dedikasi1987ArsitekturStatusKon-katedralStatus fungsionalAktifArsitekEdward F. WirtzGayaModernPeletakan batu pertama1955Selesai1957SpesifikasiKapasitas1,20...

United States Senators' investigative tour of the Mississippi Delta Joseph S. ClarkRobert F. Kennedy United States Senators Joseph S. Clark and Robert F. Kennedy toured the Mississippi Delta on April 10, 1967. At the behest of civil rights lawyer Marian Wright, Clark and Kennedy, together with two other senators, traveled to Mississippi to investigate reports of extreme poverty and starvation. Following a field hearing, they drove from Greenville to Clarksdale, stopping and touring impoverish...

 

1810 Spanish general election January - September 1810[1] 1813 → All 276 seats of the Cortes of Cádiz138 seats needed for a majorityTurnoutNA General elections to the special Cortes of Cádiz were held in Spain in 1810. At stake were all 276 seats in the Cortes of Cádiz – which served as a parliamentary Regency after Ferdinand VII was deposed by Napoleon. History During the first years of the Spanish War of Independence (1808-1814) the popular revolts of t...

 

Russian association football club based in Kazan, Tatarstan Football clubRubin KazanFull nameООО Футбольный клуб Рубин КазаньOOO Football Club Rubin Kazan[1]Nickname(s)Rubinovye, Krasno-Zelyonye (The Red-Greens)Founded20 April 1958; 66 years ago (1958-04-20)GroundAk Bars Arena Central StadiumCapacity45,379PresidentMarat SafiullinManagerRashid Rakhimov[2]LeagueRussian Premier League2023–248th of 16WebsiteClub website Home colours ...

ウンベルト・サバ(1951年) ウンベルト・サバの胸像(トリエステの公共公園で) トリエステにあるウンベルト・サバの中古書店(2008年) ウンベルト・サバ(イタリア語: Umberto Saba、1883年3月9日 – 1957年8月26日)は、生まれはウンベルト・ポリ(Umberto Poli)で、オーストリア=ハンガリー帝国からイタリアへ編入されたトリエステで主に活躍した詩人である。詩風は...

 

Uva

Disambiguazione – Se stai cercando altri significati, vedi Uva (disambigua). Disambiguazione – Acino rimanda qui. Se stai cercando altri significati, vedi Acino (disambigua). Uva L'uva è il frutto della vite (Vitis vinifera) e di altre specie o ibridi del genere Vitis. Indice 1 Botanica 2 Utilizzo 3 Proprietà di uva e derivati 4 Produzione 5 Note 6 Voci correlate 7 Altri progetti 8 Collegamenti esterni Botanica Schema della struttura di un grappolo d'uva Il grappolo d'uva è un...

 

American Mormon leader Joseph W. McMurrin First Council of the SeventyOctober 5, 1897 (1897-10-05) – October 24, 1932 (1932-10-24)Called byWilford Woodruff Personal detailsBornJoseph William McMurrin(1858-09-05)September 5, 1858Tooele, Utah Territory, United StatesDiedOctober 24, 1932(1932-10-24) (aged 74)Los Angeles, California, United States Biography portal   LDS movement portal Joseph William McMurrin (September 5, 1858 – ...

Beginnings of Puritanism in Colonial America Part of a series onPuritansThe Puritan, an 1887 statue by Augustus Saint-Gaudens, in Springfield, Massachusetts BackgroundChristianityProtestantismReformationEnglish ReformationCalvinismAnglicanismArminianismArminianism in the Church of EnglandEnglish DissentersIndependentsNonconformismEnglish PresbyterianismEcclesiastical separatism17th-century denominations in England Crucial themesDefinitions of PuritanismImpropriationPuritan SabbatarianismMille...

 

街区の例[要検証 – ノート] 街区(がいく)とは市区町村内の区画のひとつである。日常的には、街路に囲まれた一区画をいう。英語のcity blockに対応し、「ブロック」ともいう。 概要 街区は日本の行政上は「市町村内の町又は字の名称並びに当該町又は字の区域を道路、鉄道若しくは軌道の線路その他の恒久的な施設又は河川、水路等によつて区画した場合に...