Shader: Difference between revisions

From Valve Developer Community
Jump to navigation Jump to search
mNo edit summary
(Major re-write to clarify information, removed stub / pov templates)
Line 1: Line 1:
{{pov}}
==Introduction==
{{stub}}
[[category:Programming]] [[category:Glossary]]


Information about authoring shaders under the Source engine is [[Authoring_Shaders|here]].
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 piece of software that instead of executing on the CPU, it executes on the GPU.
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]].


[[Shader]]s provide great control over what is rendered, and can perform operations of vertices, pixels, and some others.
For information on authoring shaders for use in the [[Source Engine]], please see [[Authoring_Shaders|here]].


The [[Source Engine]] uses [[HLSL]] for [[shader]]s. There is another language called '''[[CG]]''' (Which stands for ''''C''' for '''G'''raphics'), which was developed alongside [[HLSL]] by [[Wikipedia:NVIDIA|NVIDIA]].
==Source Shader Types==


[http://msdn.microsoft.com/library/default.asp?url=/library/en-us/directx9_c/HLSL_Shaders.asp Microsoft HLSL website]
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.


There are typically 2 classes of shaders that you can think of. Postprocessing and per object shaders. Postprocessing shaders are effects computed on a 2D texture. This 2D texture is typically built at the end of the main render function out of all of the verts in the frame buffer. There are functions in DX to create a render target (the offline buffer - or the texture you will use) and render to that render target (this functionality is hidden to all of us sdk mod makers in higher level functions, but know it's there). Once you have information in that texture, you can use a shader to do all kinds of effects like motion blur, light bloom, depth of field, shadows, sharpen and on and on. In the source SDK, they provide a good example of this type of shader in sdk_postprocess and give comments at the top of this file (the .cpp one) as to where you should add code into the engine to actually "activate" the effect. Make sure you look at all three files so you understand what's going on (sdk_postprocess.cpp, sdk_postprocess_vs.fxc, and sdk_postprocess_ps.fxc).
===Postprocess===


Per object shaders are handled a bit differently in this engine, in that you need to specify the shader you want to use in a material file. So if you wanted to have a per pixel lit car, for example, you would need to specify that the car use your specific shader.  I'm currently working on material shaders to perform dynamic lighting and dynamic reflections and will update the page as I find out more info.
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.


There are two types of shaders. [[Pixel shader]] and [[Vertex shader]].
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>)


==See Also==
===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 ( <code>sdk_lightmap.cpp</code>, <code>sdk_lightmap_vs20.fxc</code>, and <code>sdk_lightmap_ps20.fxc</code>)
 
==Further Reading==
* [[Wikipedia:Shader]]
* [[Wikipedia:Shader]]
* [http://developer.nvidia.com/object/gpu_gems_home.html GPU Gems]
* [http://developer.nvidia.com/object/gpu_gems_2_home.html GPU Gems 2]
* [http://developer.nvidia.com/object/cg_tutorial_home.html The CG tutorial]
* [http://wraiyth.freesuperhost.com/development/tutorials/postprocess.htm Simple Post-Process Shader tutorial]
* [http://wraiyth.freesuperhost.com/development/tutorials/postprocess.htm Simple Post-Process Shader tutorial]
* [http://wraiyth.freesuperhost.com/development/tutorials/nvidiaconvert.htm Converting nVidia SDK shaders to HL2 (sample)]
* [http://wraiyth.freesuperhost.com/development/tutorials/nvidiaconvert.htm Converting nVidia SDK shaders to HL2 (sample)]
[[category:Programming]] [[category:Glossary]] [[category:Technical]]

Revision as of 07:17, 25 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.

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