Shader: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
m (mergefrom)
(Merged vertex shader)
Line 1: Line 1:
{{mergefrom|Pixel shader}}
{{mergefrom|Vertex shader}}
==Introduction==
==Introduction==


A shader is a program that runs on the graphics hardware (GPU) rather than the CPU. There are two variations of shaders, [[Pixel shader]]s and [[Vertex shader]]s, each of which performs a different task in the rendering pipeline. Shaders form a replacement for the fixed function pipeline and allow developers greater control over rendering output by providing the ability to modify pixels and vertices dynamically.
A shader is a program that runs on the graphics hardware (GPU) rather than the CPU. There are two variations of shaders, Pixel shaders and Vertex shaders, each of which performs a different task in the rendering pipeline. Shaders form a replacement for the fixed function pipeline and allow developers greater control over rendering output by providing the ability to modify pixels and vertices dynamically.


There are currently three main shader languages, [[HLSL]], [[CG]] and [http://en.wikipedia.org/wiki/GLSL GLSL]. The [[Source Engine]] uses [[HLSL]] based shaders, however [[CG]] is so similar that most [[CG]] shaders can be quickly and easily ported to [[HLSL]].
There are currently three main shader languages, [[HLSL]], [[CG]] and [http://en.wikipedia.org/wiki/GLSL GLSL]. The [[Source Engine]] uses [[HLSL]] based shaders, however [[CG]] is so similar that most [[CG]] shaders can be quickly and easily ported to [[HLSL]].


For information on authoring shaders for use in the [[Source Engine]], please see [[Authoring_Shaders|here]].
For information on authoring shaders for use in the [[Source Engine]], please see [[Authoring_Shaders|here]].
===Vertex Shaders===
A Vertex shader is a shader used for a variety of things, it's most basic goal is to transform geometry into screenspace coordinates so that the Pixel shader can rasterize an image. On a more complex scale vertex shaders are responsible for lighting, shadows, animation, along with any other tasks you might be able to come up with. Vertex shaders work with one vertex at a time and will run through a series of transforms based upon certain data.


==Source Shader Types==
==Source Shader Types==
Line 16: Line 17:
===Postprocess===
===Postprocess===


A Postprocess shader is typically a [[Pixel shader]] that works on a quad rendered across the entire screen. The quad is textured with a copy of the frame buffer, the [[Pixel shader]] can than alter and modify the rendered output to create a variety of effects, such as basic colour modification to more advanced processes such as motion blur and bloom.
A Postprocess shader is typically a Pixel shader that works on a quad rendered across the entire screen. The quad is textured with a copy of the frame buffer, the Pixel shader can than alter and modify the rendered output to create a variety of effects, such as basic colour modification to more advanced processes such as motion blur and bloom.


The Source SDK provides an example of this form of shader in the sdk_postprocess files (<code>sdk_postprocess.cpp</code>, <code>sdk_postprocess_vs20.fxc</code>, and <code>sdk_postprocess_ps20.fxc</code>)  
The Source SDK provides an example of this form of shader in the sdk_postprocess files (<code>sdk_postprocess.cpp</code>, <code>sdk_postprocess_vs20.fxc</code>, and <code>sdk_postprocess_ps20.fxc</code>)  

Revision as of 06:37, 27 July 2006

Introduction

A shader is a program that runs on the graphics hardware (GPU) rather than the CPU. There are two variations of shaders, Pixel shaders and Vertex shaders, each of which performs a different task in the rendering pipeline. Shaders form a replacement for the fixed function pipeline and allow developers greater control over rendering output by providing the ability to modify pixels and vertices dynamically.

There are currently three main shader languages, HLSL, CG and GLSL. The Source Engine uses HLSL based shaders, however CG is so similar that most CG shaders can be quickly and easily ported to HLSL.

For information on authoring shaders for use in the Source Engine, please see here.

Vertex Shaders

A Vertex shader is a shader used for a variety of things, it's most basic goal is to transform geometry into screenspace coordinates so that the Pixel shader can rasterize an image. On a more complex scale vertex shaders are responsible for lighting, shadows, animation, along with any other tasks you might be able to come up with. Vertex shaders work with one vertex at a time and will run through a series of transforms based upon certain data.


Source Shader Types

The Source Engine provides for two seperate forms of shaders, Postprocess and Per-Object, the majority of the effects and materials used within the Source Engine rely heavily on their Pixel shader components.

Postprocess

A Postprocess shader is typically a Pixel shader that works on a quad rendered across the entire screen. The quad is textured with a copy of the frame buffer, the Pixel shader can than alter and modify the rendered output to create a variety of effects, such as basic colour modification to more advanced processes such as motion blur and bloom.

The Source SDK provides an example of this form of shader in the sdk_postprocess files (sdk_postprocess.cpp, sdk_postprocess_vs20.fxc, and sdk_postprocess_ps20.fxc)

Per-Object

A Per-Object shader in the Source Engine is used on any object with the shader referenced in the relevant VMT file, such as a model or piece of brushwork. A Per-Object shader could be used to create a refractive material, modify a models vertices dynamically or other advanced rendering effects.

The Source SDK provides an example of a Per-Object shader in the sdk_lightmap files ( sdk_lightmap.cpp, sdk_lightmap_vs20.fxc, and sdk_lightmap_ps20.fxc)

Further Reading