Writing HLSL shader programs
Add an HLSL shader program
Introduction to HLSL shader programs
In Unity, you usually write shaderA program that runs on the GPU. More info
See in Glossary programs in High-Level Shader Language (HLSL). To add HLSL code to your shader asset, add the code in a shader code block.
Note: Unity also supports writing shader programs in other languages like OpenGL Shading Language (GLSL), but this isn’t generally needed or recommended.
There are two main types of shader programs you write in HLSL:
- Vertex shaderA program that runs on each vertex of a 3D model when the model is being rendered. More info
See in Glossary programs, also known as vertex shaders. These programs usually transform the position of the meshThe main graphics primitive of Unity. Meshes make up a large part of your 3D worlds. Unity supports triangulated or Quadrangulated polygon meshes. Nurbs, Nurms, Subdiv surfaces must be converted to polygons. More info
See in Glossary from object space to clip space, and pass data such as UV coordinates to the fragment shader program.
- Fragment shader programs, also known as fragment shaders or pixelThe smallest unit in a computer image. Pixel size depends on your screen resolution. Pixel lighting is calculated at every screen pixel. More info
See in Glossary shaders. These programs usually calculate and output the color of each pixel on-screen.
To make it easier to write shaders across different HLSL versions, graphics APIs, and platforms, Unity provides shader libraries with preprocessor macros. For more information, refer to Shader methods in the Universal Render Pipeline (URP) or Shader methods in the Built-In Render Pipeline.
For general information on writing HLSL, refer to the HLSL documentation on the Microsoft website.
Additional resources
Writing HLSL shader programs
Add an HLSL shader program
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。